Information générale
Catégorie:
Bases de données
Titre:
What are the tables names in my database :)
>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!
................
here's the Function provided for me by Cathi Gero
Public Function GetTables(ByVal 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
Public Sub DisplayTableNames()
Dim cnn As OleDbConnection
Dim tblNames As New DataTable()
Dim strConn As String
strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" + _
"Data Source=C:\NorthWind.mdb;" + _
"Mode=Share Deny None"
cnn = New OleDbConnection(strConn)
tblNames = GetTables(cnn)
' Please fill up the code
' that will display all the table names
' in the Northwind.mdb using MsgBox
' using loop statement (i dunno, maybe you will give me something
' like for i = 1 to tblNames.Count or something else)
' ....
' ....
End Sub
1. There's an error message that appears on the GetTables function on
the conn.Open()
An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred in system.data.dll
2. pls give me the code for displaying the names of tables using msgbox
3. pls test your solution first before replying. tnx! :))
Suivant
Répondre
Voir le fil de ce thread
Voir le fil de ce thread à partir de ce message seulement
Voir tous les messages de ce thread
Voir tous les messages de ce thread à partir de ce message seulement