CodeItBetter Programming Another VB Programming Blog

How to connect Oracle from VB

Posted on January 4, 2009
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
'Database - How to connect Oracle from VB
'Here is code and connection strings to connect Oracle from vb:

Dim conn As ADODB.Connection
 
' Open a connection using Oracle ODBC.
Set conn = New ADODB.Connection
conn.ConnectionString = "Driver={Microsoft ODBC for Oracle};" & "UID=user_name;PWD=user_passsword"
conn.Open
 
'Open the table as in:

Dim rs As ADODB.Recordset
 
' Open the table.
Set rs = New ADODB.Recordset
rs.Open "TableName", conn, 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.EOF
    txt = ""
    For Each fld In rs.Fields
        txt = txt & Trim$(fld.Value) & ", "
    Next fld
    If Len(txt) > 0 Then txt = Left$(txt, Len(txt) - 2)
    List1.AddItem txt
    rs.MoveNext
Loop
 
'Finally close the recordset and close the connection:
rs.Close
conn.Close
Filed under: Database Leave a comment
Comments (1) Trackbacks (0)
  1. thanks it s usefull to me


Reply

( Cancel )

 

No trackbacks yet.