How to evaluate the tables relationships using ado.net/dataset

C

CV

I have a list of 2 tables, using asp.net/ado.net I want to find out the
foreign key relationships based on the physical structure of the
database. Any idea how can that be done?

Thanks,
C.
 
M

Miha Markic [MVP C#]

Hi CV,

A generalized way is through OleDbConnection.GetOleDbSchemaTable method.
Other way would be to query database directly using its DDL (syntax depends
on the database).
 
C

CV

Thanks. I would look into it. Any examples would be great too.
Basically I want to reterive two tables from database and want to find
the relationship between them on the front end level.

CV.
 
M

Miha Markic [MVP C#]

Hi CV,

You'll probably need something like (writting out of my head):
DataTable schemaTable =
conn.GetOleDbSchemaTable(OleDbSchemaGuid.Foreign_Keys,
new object[] {null,
null, "OneTableName", null, null, "OtherTableName"});
and one select for inverted roles

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


See help on OleDbSchemaGuid.Foreign_Keys Field enumeration memeber on what
those parameters add.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top