Trying to write ADO code in VB.Net environment

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,
I am upgrading my database componenet from VB6.0 to VB.net but would like to use ADO for database operation. Am trying to retrieve no of tables in a database using connection.openschema method of ADODB. It works fine in VB6.0 but blows of in VB.net. The code looks like
rsReadOnly = New ADODB.Recordset


rsReadOnly = goConnection.OpenSchema(ADODB.SchemaEnum.adSchemaTables, New Object() {Nothing, Nothing, Nothing, "TABLE"})
The Error message is :System.NullReferenceException - Object variable or With block variable not set.

Very Urgent........
 
The following code will put all the table information in a datagrid and
indicate the number of tables of all table types.

'need reference to ADODB
Try
Dim Conn As New ADODB.Connection
Conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=" & Application.StartupPath & "\test.mdb"
Conn.Open()
Dim rs As New ADODB.Recordset
rs = Conn.OpenSchema(ADODB.SchemaEnum.adSchemaTables)
Dim MyTable As New DataTable
Dim da As New Data.OleDb.OleDbDataAdapter
da.Fill(MyTable, rs)
Me.DataGrid1.DataSource = MyTable
Me.DataGrid1.Refresh()
MsgBox(MyTable.Rows.Count.ToString)
Catch ex As Exception
MsgBox(ex.Message)
End Try


Lokanath said:
Hi,
I am upgrading my database componenet from VB6.0 to VB.net but would like
to use ADO for database operation. Am trying to retrieve no of tables in a
database using connection.openschema method of ADODB. It works fine in VB6.0
but blows of in VB.net. The code looks like
rsReadOnly = New ADODB.Recordset


rsReadOnly =
goConnection.OpenSchema(ADODB.SchemaEnum.adSchemaTables, New Object()
{Nothing, Nothing, Nothing, "TABLE"})
The Error message is :System.NullReferenceException - Object
variable or With block variable not set.
 
Back
Top