tags:

views:

414

answers:

5

Consider i have 'n' tables which are created using MS Access.

Now i need to find the relationship among the tables. i.e How the tables are interlinked as changes made in a table will be reflected other table.?

is there any to find this using c#

+1  A: 

Either Google for MSysObjects (see this, for instance) or use GetSchema on OleDbConnection.

Anton Gogolev
+2  A: 

I am not sure how to find from C#. But in ms-access we can see easily find.

Open access database file. and click on Menu (Tools->Relationships). You can view the current relation ships.

Thanks and regards Haranadh

Haranadh
its used to create relationships and nothing i am able to view there now
Arunachalam
@Arunachalem: You can add the existing tables to diagram and then are relationship shown.
TcKs
This answer is mostly incorrect. The relationships window only represents what you the user put in there, it has nothing whatsoever to to with how the tables are related. It also is by no means comprehensive. sry
Praesagus
@Praesagus: you are incorrect. If there is RI defined in your source database, and you are viewing the source database in Access, the relationships window will represent all the relationships defined. True, in a front end, you draw lines between tables that won't exist in the back end, but these are not relationships (which will have infinity or 1 at either or both ends of the line), but just default joins. These default joins can be set up between tables and queries, too, but RI cannot be enforced between them.
David-W-Fenton
A: 

I don't believe you need to automate Access to do this. All that's needed, I think, is ADOX. This article shows how to use ADOX to copy relationships in VBA:

ACC2002: How to use ADOX to Import Relationships

Relationships are defined under the ADOX.Table.Keys property. I can't help you convert that to C#, but that code shows you what parts of the ADOX object model you need to use for this and ought to help you figure it out, I hope.

David-W-Fenton
A: 

DataTable schemaTable = oledbConnection.GetOleDbSchemaTable(OleDbSchemaGuid.Foreign_Keys, new object[] {null, null, "OneTableName"});

or

DataTable schemaTable = oledbConnection.GetOleDbSchemaTable(OleDbSchemaGuid.Foreign_Keys, new object[] {null, null, "OneTableName", null, null, "OtherTableName"});

bahareh