General discussion

Locked

Connecting to a Oracle Database using VB.net

By ppburli ·
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 conversation is currently closed to new comments.

3 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

If you are just pulling stuff in

by Tony Hopkinson In reply to Connecting to a Oracle Da ...

The DataReader classes are lighter.

Then you just do
While Reader.Read()
{
MyArray[Index] = Reader["username"].ToString();
Index ++;
}

or some such.

Personally I'd be knocking up a class to hold the record and hold generic list of them....

Collapse -

OleDB

by consultingforce In reply to Connecting to a Oracle Da ...

I have done many Oracle projects with VB.NET and would tell you first that you would want to eliminate the OleDB and replace it with a native Oracle client.

What I find works extremely well for retrieving data from Oracle is the use of "weak bound ref cursors." this will basically give you a "bucket" of data from Oracle that you can use as a dataset, datatable, etc.

Hope this helps!

Thanks,

B

Collapse -

connecting to oracle database with vb.net

by Preetha R In reply to Connecting to a Oracle Da ...

hello sir.......i am doing my final year project...while connecting to the database i am getting the error ORA-01017: invalid username/password; logon denied
Pls suggest me for this error...am waiting for ur reply...i hv given the code as ....
Imports System.Data.OleDb

Public Class Form1
Dim inc As Integer
Dim maxrows As Integer = 0
Dim con As New OleDb.OleDbConnection
Dim da As New OleDb.OleDbDataAdapter
Dim ds As New DataSet
Dim sql As String
Dim mycon As OleDbConnection
Dim mycommand As OleDbCommand
Dim ra As Integer
Private Sub connect()
con.Open()
sql = "select * from sample"
da = New OleDb.OleDbDataAdapter(sql, con)
ds.Clear()
da.Fill(ds, "sample")
maxrows = ds.Tables("sample").Rows.Count
MsgBox("form load" & maxrows)
inc = -1
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
myCommand = New OleDbCommand("insert into sample values('" & ComboBox1.Text & "','" & TextBox2.Text & "')", con)
ra = mycommand.ExecuteNonQuery()
mycommand = New OleDbCommand("commit", con)
End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
con.ConnectionString = "Provider=MSDAORA.1;UserID=scott;password=tiger; database=railways"
connect()
End Sub
End Class

Back to Software Forum
3 total posts (Page 1 of 1)  

Related Discussions

Related Forums