Share via


How to get all the Table names stored in a ADO recordset?

Question

Wednesday, September 17, 2014 5:20 PM

I am doing a vb.net project, and I used MS access 2002-2003 database. In my project I need to display the list of tables(recordsets) stored in the database. Can anyone help me??

Thank you in advance

All replies (5)

Wednesday, September 17, 2014 7:30 PM âś…Answered

The counterpart to ADODB is ADOX.

    Public Sub ListAccessTablesADOX()

        Dim cnn As New ADODB.Connection
        Dim cat As New ADOX.Catalog
        Dim tbl As ADOX.Table
        Dim prop As ADOX.Property

        cnn.Open("Provider=Microsoft.Jet.OLEDB.4.0;" & _
                             "Data Source=e:\My Documents\db10.mdb;" & _
                             "Jet OLEDB:Engine Type=4;")

        cat.ActiveConnection = cnn

        For Each tbl In cat.Tables

            Console.WriteLine(tbl.Name)
            Console.WriteLine(tbl.Type)
            Console.WriteLine(tbl.DateCreated)
            For Each prop In tbl.Properties
                Console.WriteLine(prop.Name & ":" & prop.Value)
            Next prop

        Next tbl

        cnn.Close()

        System.Runtime.InteropServices.Marshal.ReleaseComObject(cat)
        System.Runtime.InteropServices.Marshal.ReleaseComObject(cnn)

        cat = Nothing
        cnn = Nothing

    End Sub

Paul ~~~~ Microsoft MVP (Visual Basic)


Wednesday, September 17, 2014 5:36 PM

A recordset and a DataBase are two different things. 

You can show it by using an OleDBDataAdapter and then do a FillSchema with a DataSet

http://msdn.microsoft.com/en-us/library/9y8wt27x(v=vs.110).aspx

Success
Cor


Wednesday, September 17, 2014 6:59 PM

Sorry , I am using ADO data control to access the MS ACCESS . In that I need to retrieve the names of all the Tables stored. So is there any method present in ADODB ,which displays all the tables stored inside??


Wednesday, September 17, 2014 7:36 PM

And if you want to return in an ADO Recordset see the below link. There is some filtering that may be required (the schema method is recommended).

http://stackoverflow.com/questions/201282/how-to-get-table-names-from-access

Paul ~~~~ Microsoft MVP (Visual Basic)


Thursday, September 18, 2014 8:25 PM

Thank you