How to Open an Oracle database using ADO
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 38 39 40 | 'Database - How to Open an Oracle database using ADO 'Use a connect string as in: 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 'Note that you need to fill in a valid user name, password, and table for your 'database. 'Note also that this example uses the Microsoft ODBC driver for Oracle. Oracle 'also supplies drivers that you may be able to use instead. 'This example 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 rs.Close conn.Close |