anoniem Geplaatst: 9 januari 2004 Delen Geplaatst: 9 januari 2004 Is er iemand die weet hoe ik de namen van de tabellen uit een bepaalde database kan opvragen? Ik wil alle tabellen van een bepaalde database doorlopen, maar de namen van de tabellen kunnen telkens verschillen. Is er iemand die weet hoe ik de namen van de tabellen kan opvragen? Quote Link naar reactie
anoniem Geplaatst: 11 januari 2004 Auteur Delen Geplaatst: 11 januari 2004 Hier bij een listing van een stukje code afkomstig van msdn. Voor meer info zie: [url]http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndao/html/daotoadoupdate_topic6.asp[/url] ---- Retrieving Schema Information Both DAO and ADOX contain collections of objects that can be used to retrieve information about the database's schema. By iterating through the collections, it is easy to determine the structure of the objects in the database. The following code demonstrates how to print the name of every table in the database by looping through the DAO TableDefs collection and the ADOX Tables collection. DAO Sub DAOListTables() Dim db As DAO.Database Dim tbl As DAO.TableDef ' Open the database Set db = DBEngine.OpenDatabase(".\NorthWind.mdb") ' Loop through the tables in the database and print their name For Each tbl In db.TableDefs Debug.Print tbl.Name Next End Sub ADOX Sub ADOListTables() Dim cat As New ADOX.Catalog Dim tbl As ADOX.Table ' Open the catalog cat.ActiveConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" & _ "Data Source=.\NorthWind.mdb;" ' Loop through the tables in the database and print their name For Each tbl In cat.Tables If tbl.Type <> "VIEW" Then Debug.Print tbl.Name Next End Sub With DAO the TableDef object represents a table in the database and the TableDefs collection contains a TableDef object for each table in the database. This is similar to ADO, in which the Table object represents a table and the Tables collection contains all the tables. However, unlike DAO, the ADO Tables collection may contain Table objects that aren't actual tables in your Microsoft Jet database. For example, row-returning, non-parameterized Microsoft Jet queries (considered Views in ADO) are also included in the Tables collection. To determine whether the Table object represents a table in the database, use the Type property. The following table lists the possible values for the Type property when using ADO with the Microsoft Jet Provider. ---- Suc6 Quote Link naar reactie
Aanbevolen berichten
Om een reactie te plaatsen, moet je eerst inloggen