By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,524 Members | 1,519 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,524 IT Pros & Developers. It's quick & easy.

Trying to write ADO code in VB.Net environment

P: n/a
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.adSchemaT ables, New Object() {Nothing, Nothing, Nothing, "TABLE"})
The Error message is :System.NullReferenceException - Object variable or With block variable not set.

Very Urgent........
--
System Analyst
Nov 20 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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" <it*******@yahoo.com> wrote in message
news:44**********************************@microsof t.com...
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.adSchemaT ables, New Object()
{Nothing, Nothing, Nothing, "TABLE"}) The Error message is :System.NullReferenceException - Object variable or With block variable not set.
Very Urgent........
--
System Analyst

Nov 20 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.