Question

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).

Was it helpful?

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.

OTHER TIPS

I think what you mean is that for each FOREIGN KEY in the schema you want to discover the name of the referenced table. From a quick google it seems this may not be possible:

Microsoft Connect: DbConnection.GetSchema: no ways to get foreign keys' columns

...which is strange because with ADO classic's (COM, not .NET) OpenSchema method you can.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top