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"

'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

'Finally close the recordset and close the Conn_Dataection:


ecommerce website development said...

Well you have great code here that will be very useful for me.. I will implement this and try out.. I often visit your blogs as you share some good some and I love to learn more on VB.

Anonymous said...


sap project systems said...

I love to visit your blog as I do find so many useful source codes that support me when developing applications. I have implemented the above one too and is able to successfully connect the database using Visual Basic. Thanks

Kami.Genius said...


What if when you want the specified data from table like the date range or some thing...

It is very helpfull for me for my project...

Rijz said...
This comment has been removed by the author.
Rijz said...

hi. am beginner in oracle and visual basic. I have installed VB 2008 and oracle 11g express edition. My OS is windows 7, i want to know how to connect the oracle from visual basic??? Can u please help me out. I dont find Microsoft OLE DB Provider for Oracle (Database Engine) driver to change the database connection in VB. How can i install n hw can i knw that it is already installed in ma system or not. And i tried using the above code n failed may be because i went wrong some where. How can i resolve this??

IVAN said...

Hi,thanks so much for the great code,i have a task to accomplish and the task is to extract data from an sql server database to oracle,i'd like to accomplish this task using a vb solution.please any code that can help me in this regard is highly welcomed.


Anonymous said...


Anonymous said...

I am not able to connect oracle database still. could you please, guide me?

Web Designers Pitampura said...

Blogging is the new poetry. I find it wonderful and amazing in many ways.

Post a Comment

Powered by Blogger