Q

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? 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 

        ODC.Open() 
        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 
        Next 
        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 
            Next 
            Label1.Text += vbCrLf 
        Next

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

Dig deeper on WCF (Windows Communication Foundation)

Pro+

Features

Enjoy the benefits of Pro+ membership, learn more and join.

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

0 comments

Oldest 

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:

SearchSoftwareQuality

SearchCloudApplications

SearchAWS

TheServerSide

SearchWinDevelopment

Close