Search code examples
c#ms-accessschemaoledb

C# / Access Getting Primary Keys from Access 2003


I'm using OleDb to interact with an Access database, and I'm trying to find out how to get the primary keys of each table, but in such a way that they are associated with the tables. In other words, I don't just want a flat list of the primary key column names--I want to be able to determine which table they belong to.

Any idea how to do this? I've used the GetSchema() method to get a table of tables, but that table's information does not appear to include primary keys (or any other indexes, for that matter).


Solution

  • Ok--did a little outputting of column names and got a better understanding of how the schema tables are related.

    To do this, pass the string "Indexes" to the GetSchema() method. Each record in the index table contains both the table name and whether or not the index is the primary key.