Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleUse ADOX to list the tables in an Access database and give their types in Visual Basic .NET
DescriptionThis example shows how to use ADOX to list the tables in an Access database and give their types in Visual Basic .NET.
KeywordsADOX, Access, database, table, table type, VB.NET
CategoriesDatabase
 
First add references to the COM libraries:

  • Microsoft ActiveX Data Objects 2.6 Library
  • Microsoft ADO Ext. 2.6 for DLL and Security

(Or whatever your versions are.)

When you click the List Tables button, the following code executes. It opens the database and uses the ADOX catalog to learn about the database. It loops through the Tables collection adding the table names and types to a ListView control. Note that this collection includes tables that you build (TABLE type), Access tables (ACCESS TABLE type), system tables (SYSTEM TABLE type), and queries (VIEW type).

 
Private Sub btnListTables_Click(ByVal sender As _
    System.Object, ByVal e As System.EventArgs) Handles _
    btnListQueries.Click
    lvwTables.Items.Clear()

    ' Open the connection.
    Dim conn As New ADODB.Connection
    conn.ConnectionString = _
        "Provider=Microsoft.Jet.OLEDB.4.0;" & _
        "Persist Security Info=False;" & _
        "Data Source=" & txtDatabase.Text
    conn.Open()

    ' Make a catalog for the database.
    Dim cat As New ADOX.Catalog
    cat.ActiveConnection = conn

    ' List the catalog's tables.
    For i As Integer = 0 To cat.Tables.Count - 1
        Dim lvi As ListViewItem = _
            lvwTables.Items.Add(cat.Tables(i).Name)
        lvi.SubItems.Add(cat.Tables(i).Type)
    Next i

    conn.Close()

    lvwTables.Columns(0).Width = -2
    lvwTables.Columns(1).Width = -2
End Sub
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated