Showing posts with label Connect Oracle. Show all posts
Showing posts with label Connect Oracle. Show all posts

Thursday, March 24, 2011

Connect Oracle Database using Visual Basic



'How to connect Oracle Database from Visual Basic
'Sample code and connection strings to connect Oracle using Visual Basic:

Dim conn As ADODB.Connection

' Open a Conn_Dataection using Oracle ODBC.
Set Conn_Data = New ADODB.Connection
Conn_Data.ConnectionString = "Driver={Microsoft ODBC for Oracle};" & "UID=user_name;PWD=user_passsword"
Conn_Data.Open

'Open the table as in:

Dim rs_Data As ADODB.Recordset

' Open the table.
Set rs_Data = New ADODB.Recordset
rs_Data.Open "TableName", Conn_Data, adOpenDynamic, adLockOptimistic, adCmdTable

'Enter the user name password and table name as per the database.
'it must be valid one.

'To reads the data from the table and displays the values in a ListBox

' List the data.
Do While Not rs_Data.EOF
    txt = ""
    For Each fld In rs_Data.Fields
        txt = txt & Trim$(fld.Value) & ", "
    Next fld
    If Len(txt) > 0 Then txt = Left$(txt, Len(txt) - 2)
    List1.AddItem txt
    rs_Data.MoveNext
Loop

'Finally close the recordset and close the Conn_Dataection:
rs_Data.Close
Conn_Data.Close
 
Powered by Blogger