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

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

    When you register, you'll begin receiving targeted emails from my team of award-winning writers. Our goal is to keep you informed on recent service-oriented architecture (SOA) and SOA-related topics such as integration, governance, Web services, Cloud and more.

    Hannah Smalltree, Editorial Director

    By submitting your registration information to SearchSOA.com you agree to receive email communications from TechTarget and TechTarget partners. We encourage you to read our Privacy Policy which contains important disclosures about how we collect and use your registration and other information. If you reside outside of the United States, by submitting this registration information you consent to having your personal data transferred to and processed in the United States. Your use of SearchSOA.com is governed by our Terms of Use. You may contact us at webmaster@TechTarget.com.

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