Ask the Expert

In VB.Net, how can I use Tabledef to display a list of Access tables in a combo box?

In VB6, I use Tabledef to get the list of tables in an Access database and display it in a combo box. How do you implement this in VB.Net?

    Requires Free Membership to View

Here is how you can retrieve schema information from a database using ADO.NET. To use this code, create a data connection and call it ODC. Paste this code into a button on a form and add a label named label1 (You should use better names in real life ). This code will iterate through all database objects and print their names and values to the label control.

        Dim DT As DataTable 
        Dim SchemaGUID As OleDb.OleDbSchemaGuid 
        Dim MyRow As DataRow 
        Dim MyCol As DataColumn 

        DT = ODC.GetOleDbSchemaTable(SchemaGUID.Tables, Nothing) 
        Label1.Text = "" 

        For Each MyCol In DT.Columns 
            If Not DT.Rows(0).IsNull(MyCol.ColumnName) Then 
                Label1.Text += MyCol.ColumnName & "  :  " 
            End If 
        Label1.Text += vbCrLf 
        For Each MyRow In DT.Rows 
            For Each MyCol In DT.Columns 
                If Not MyRow.IsNull(MyCol.ColumnName) Then 
                    Label1.Text += MyRow(MyCol.ColumnName) & "  :  " 
                End If 
            Label1.Text += vbCrLf 

That should give you what you need to know. Just fill a combo box with the TABLE_NAME from each row in the DataTable.

The GetOleDbSchemaTable method of the OleDbConnection object provides schema data in ADO.NET. You provide this method with a GUID retrieved by calling the appropriate method of the OleDb.OleDbSchemaGuid object. Using these objects, you can retrieve a wealth of information about a database schema.

This was first published in October 2002

There are Comments. Add yours.

TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to: