Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
What are the tables names in my database :)
Message
Information générale
Forum:
ASP.NET
Catégorie:
Bases de données
Divers
Thread ID:
00690707
Message ID:
00691553
Vues:
12
You need to modify the connection string (strConn) to fit your scenario. That was just a sample string. The error you are generating is because the connection string either can't find the database in your C:\ directory or security rights. The easiest way to create a connection string is to use the Server Explorer. The sample code works for me. I try to test all code before I post it.

>>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! :))
-----------------------------------------

Cathi Gero, CPA
Prenia Software & Consulting Services
Microsoft C# / .NET MVP
Mere Mortals for .NET MVP
cgero@prenia.com
www.prenia.com
Weblog: blogs.prenia.com/cathi
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform