none
List Table Names from Microsoft Access RRS feed

  • Question

  •  

    I am going to be using .mdb files that have an unspecified number of tables in them. Each table will contain the same columns, but I will not know the table names. The column names typically relate to the day of the week, so they would be "01", "02", "03", ..., "31"

     

    Since not all of the days of the week will have a table, I get an error when it is not found. I do not want to keep running into errors every time a table is not found. To speed up my application, I would like to be able to dynamically create a list of the table names, so that I do not need to worry about the errors occurring and slowing down the process.

     

    Can anyone guide me through this?

     

    Thank you,
    KJAK

    Monday, August 6, 2007 6:38 PM

Answers

  • You can use GetOleDbSchemaTable to retrieve the table names:

     

    Code Snippet

    Dim DatabaseConnection As New System.Data.OleDb.OleDbConnection

    Dim SchemaTable As DataTable

    DatabaseConnection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _

    "Data Source=C:\Test Files\db1 XP.mdb"

     

    DatabaseConnection.Open()

    SchemaTable = DatabaseConnection.GetOleDbSchemaTable(System.Data.OleDb.OleDbSchemaGuid.Tables, _

    New Object() {Nothing, Nothing, Nothing})

     

    Dim RowCount As Int32

    For RowCount = 0 To SchemaTable.Rows.Count - 1

    Select Case SchemaTable.Rows(RowCount)!TABLE_TYPE.ToString

    Case "TABLE", "PASS-THROUGH", "LINK"

    Console.WriteLine(SchemaTable.Rows(RowCount)!TABLE_NAME.ToString)

    Case Else

    'Probably a system table or view

    End Select

    Next RowCount

     

    DatabaseConnection.Close()

     

     

    Monday, August 6, 2007 7:48 PM