Results 1 to 2 of 2

Thread: Getting metadata from Access database

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2000
    Posts
    3

    Post

    I have an Access 97 database, and I need to get the column names from a specific table and use these as headings in a listview control. Can this be done through the data control in VB or do I need to use some kind of SQL statement?

    Even just an example on how to get metadata from an access database would be great.

    Thanks


  2. #2
    New Member
    Join Date
    Jan 2000
    Location
    Kennesaw, GA
    Posts
    5
    I think this would work:

    Dim db as Database
    Dim tDef as TableDef
    dim i as Integer
    dim arrColumnNames() as String


    Set db = OpenDatabase("c:\databases\somedatabase.mdb")
    Set tDef = db.Tabledefs("NameOfYourTable")

    Redim arrColumnNames(0 to tdef.fields.count)

    For i = 0 to tdef.fields.count
    arrColumnNames(i)=tDef.Fields(i).Name
    Next i

    Set tdef = Nothing
    Set db = Nothing


    That's the DAO way to do it. You could also do it using
    ADO(X), but I still find DAO easier to work with for
    Access databases. Just old-fashioned I guess. Hope this
    helps.

    G.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width