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

  • Thread starter Thread starter CV
  • Start date Start date
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.
 
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).
 
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.
 
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.
 
Back
Top