Home > How-To Library > Database
How to connect Oracle from VB
**************************************************************** * © 2007 CodeItBetter http://www.codeitbetter.com * * This notice MUST stay intact for legal use * **************************************************************** '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
If you would like to submit your code here please us. Do not forget to mention your name. We are always thankful to each and everyone of you who submitted their code here.