Here is some sample code that allows you to retrieive the table names using the OleDbConnection object. It uses the GetOleDbSchemaTable method that allows you to query all kinds of information about your database. The object returned is a DataTable filled with the Table Information:
Public Function GetTables(conn As OleDbConnection) As DataTable
conn.Open()
Dim schemaTable As DataTable = _
conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, _
New Object() {Nothing, Nothing, Nothing, "TABLE"})
conn.Close()
Return schemaTable
End Function
>im using an mdb database (Microsoft Access)
>i made my oledbconnection thru code:
>Dim cnn As OleDbConnection
>Dim strConn As String
>strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" + _
>"Data Source=C:\mydata.mdb;" + _
>"Mode=Share Deny None"
>cnn = New OleDbConnection(strConn)
>
>dragging the tables from the server explorer into my form is not appropriate for my application, because additional tables might be added to the database in the future.
>what i want is to display all the table names inside "mydata.mdb" on myListBox control.
>do i need additional objects such as oledbcommand,...
>pls fill up the missing code. thanks a lot!
-----------------------------------------
Cathi Gero, CPA
Prenia Software & Consulting Services
Microsoft C# / .NET MVP
Mere Mortals for .NET MVP
cgero@prenia.comwww.prenia.comWeblog: blogs.prenia.com/cathi