get a list of all tables in a database

  • 13 years ago

    Hi, is it possible to get a list of all the table names in a database? (vb6)

    ie: so the user can select a table to get data from, from a drop down list

  • 13 years ago

    I worked it out.

    Here is the code I used. It lists all tables that have "IN" at the start of their name.


    Dim Cnxn As ADODB.Connection
       Dim rstSchema As ADODB.Recordset
       Dim strCnxn As String
       Set Cnxn = New ADODB.Connection
       strCnxn = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\products.mdb"
       Cnxn.Open strCnxn
       Set rstSchema = Cnxn.OpenSchema(adSchemaTables)
       Do Until rstSchema.EOF
          If Mid(rstSchema!TABLE_NAME, 1, 2) = "IN" Then
          List1.AddItem Mid(rstSchema!TABLE_NAME, 3)
          End If
       ' clean up
       Set rstSchema = Nothing
       Set Cnxn = Nothing

Post a reply

Enter your message below

Sign in or Join us (it's free).


Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“XML is like violence - if it's not working for you, you're not using enough of it.”