Results 1 to 2 of 2

Thread: Find Primary Key With ADO

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jun 2000
    Posts
    24

    Question

    I have a connection to an Access DB with ADO.
    How can I get the Primary Key name field with ADO ?

  2. #2
    Guru Clunietp's Avatar
    Join Date
    Oct 1999
    Location
    USA
    Posts
    1,844
    here ya go

    Code:
        Dim cn As ADODB.Connection
        Dim ax As ADOX.Catalog
        Dim tbl As ADOX.Table
        Dim ky As ADOX.Key
            
        Set cn = New Connection
        
        cn.Open "Provider=Microsoft.JET.OLEDB.4.0;Data Source=Nwind.mdb"
        
        Set ax = New Catalog
        
        ax.ActiveConnection = cn
        
        Set tbl = ax.Tables("Customers")
        
        For Each ky In tbl.Keys
            MsgBox ky.Type  'returns KeyTypeEnum
        Next ky
        
        'cleanup.....

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