Connecting to a Oracle Database using VB.net - TechRepublic
General discussion
December 4, 2008 at 05:47 AM
ppburli

Connecting to a Oracle Database using VB.net

by ppburli . Updated 14 years, 5 months ago

Have looked for the solution everywhere and finally found the below. Hope this will help someone.

I have a question though can someone help me with transfering the data from the adaptor to a array.

Sub Connectdb()
‘redirect to error handler
On Error GoTo ErrorText

‘For database connection
Dim conn As New OleDbConnection()

‘Step 1.
‘set connection parameters
‘Parameters for database connection
‘Change the values to those applicable to your database
Dim datasource As String, username As String, password As String
‘Replace with Connect String as TNSNames
datasource = “orcl9i.idc.oracle.com”
‘Username
username = “ORANET”
‘Password
password = “ORANET”

‘set provider and connection parameters for database connection
‘get the connection parameters from connectionParams.vb file
Dim connectionString As String = “Provider=OraOLEDB.Oracle” & _
“;Data Source=” + datasource & _
“;User ID=” + username & _
“;Password=” + password & _
“;OLEDB.NET=true” ‘using OLEDB .Net Data Provider features

‘Connection to datasource, using connection parameters given above
conn = New OleDbConnection(connectionString)

‘Open database connection
conn.Open()
‘Instantiate OleDbDataAdapter to create DataSet
Dim oAdapter As OleDbDataAdapter = New OleDbDataAdapter()

‘Fetch Product Details
oAdapter.SelectCommand = New OleDbCommand(“select username, osuser, v$session”, conn)

conn.Close()
end Sub

This discussion is locked

All Comments