Ga naar inhoud

Database-tabellen doorlopen in VB6.0


Aanbevolen berichten

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
Link naar reactie

Om een reactie te plaatsen, moet je eerst inloggen

Gast
Reageer op dit topic

×   Geplakt als verrijkte tekst.   Herstel opmaak

  Er zijn maximaal 75 emoji toegestaan.

×   Je link werd automatisch ingevoegd.   Tonen als normale link

×   Je vorige inhoud werd hersteld.   Leeg de tekstverwerker

×   Je kunt afbeeldingen niet direct plakken. Upload of voeg afbeeldingen vanaf een URL in

  • Populaire leden

    Er is nog niemand die deze week reputatie heeft ontvangen.

  • Leden

    Geen leden om te tonen

×
×
  • Nieuwe aanmaken...