Thursday, March 4, 2010

Linking VB 2008 with Oracle

Here is the code to display the contents of the table in oracle in a DataGrid control in Visual Basic 2008....

Initally declare the following code in the "General Declarations."

Imports Oracle.DataAccess.Client

Then use a command button to initiate the process of displaying the contents in data grid from the table(in its click event),



Dim oradb As String = "user id=tiger;password=tiger;data source=localhost"



Dim conn As New OracleConnection()

conn.ConnectionString = oradb

conn.Open()

Dim sql As String = "select * from stu" ' Visual Basic

Dim cmd As New OracleCommand(sql, conn)

cmd.CommandType = CommandType.Text


DataGridView1.DataSource = conn.DataSource

Dim da As OracleDataAdapter

Dim cb As OracleCommandBuilder

Dim ds As DataSet

da = New OracleDataAdapter(cmd)

cb = New OracleCommandBuilder(da)

ds = New DataSet()

da.Fill(ds)

DataGridView1.DataSource = ds.Tables(0)

2 comments:

  1. hi please tell this with an example

    ReplyDelete
  2. Will Explain soon....And @ Thanigai - What exactly can't u get out of this, so that Accordingly I would explain....I thought this would be sufficient...

    ReplyDelete