Retrieving Primary Key

  • 19 years ago

    Using ADO, is there a way to retrieve the Primary Key of an Access Database?  Since there is no such thing as an Index in ADO, I can't use Index.PrimaryKey or whatever it is... But I'm working on a synchronization between databases over TCP/IP and my only snag is this Primary Key problem.  Any help would be appreciated.

  • 19 years ago

    Use the OpenSchema command. This retrieves a recordset with lots of information in it regarding the database. (Try the adSchemaPrimaryKeys constant)

  • 19 years ago

    Hey James-


    I used the OpenSchema and the adSchemaPrimaryKeys, but it only returns the TABLENAME.  The TABLECATALOG field is always empty as is the TABLESCHEMA field.  I also tried using the adSchemaIndexes constant, but that only returns the INDEXNAME and the TABLENAME and Type.  Type is easy to get anyway... Under the INDEXNAME I get "PrimaryKey" for one value.  Other values seem to be picked from outside the table.  Here is what I used to open a recordset:


    Set rst = conn.OpenSchema(adSchemaIndexes, Array(Empty, Empty, Empty, Empty, "Orders"))


    This is odd because some values for INDEX_NAME are not even in the Orders table at all!  I am baffled as to how this works.  Any help is appreciated.



    UPDATE
    I just figured it out.  The OpenSchema Method thing lists only three field names for adSchemaIndexes.  Actually, there are 25 fields.  I was playing around and changed my code.  I added this: For x = 0 to rst.Fields.Count - 1    and then I just message boxed all the values.  The field name popped up at around x = 23.  Hehehehe Sorry about that.  Hope this helps anyone else with a similar problem.

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Java is to JavaScript what Car is to Carpet.” - Chris Heilmann