Getting FK->PK relationships

  • Thread starter Thread starter David Thielen
  • Start date Start date
D

David Thielen

Hi;

We have a .NET app where we have to use the ADO.NET ODBC connector
OdbcConnection to get metadata from a database.

We can get column information using:

using (OdbcConnection conn = new OdbcConnection(connStr))
{
conn.Open();
string[] restrictions = new string [] { null, null,
table.FullName };
DataTable schemaTable = conn.GetSchema("columns",
restrictions);
....

And this gives us each column's name, data type, and remarks. That all
works great and appears to supported by most ODBC drivers.

However, we also need to get the foreign key -> primary key
relationships. So for example the column OrderItem.OrderId we need to
know it is a FK pointing to Order.OrderId.

How can we do this? Preferably in a manner that works for all ODBC
drivers. But if not, then vendor specific code (I assume a select) for
Access, Firebird, and Progress.

thanks - dave

david@[email protected]
Windward Reports -- http://www.WindwardReports.com
me -- http://dave.thielen.com

Cubicle Wars - http://www.windwardreports.com/film.htm
 
I am not sure you can do this generically with an ODBC connector. If I am
correct, you will have to write database specific routines and call the
connector through a factory. If you have to go this route, I would consider
building on an open/shared source implementation like the Enterprise
Library.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

Blog:
http://feeds.feedburner.com/GregoryBeamer

*********************************************
| Think outside the box |
*********************************************
 
We're doing exactly that -
http://www.windwardreports.com/open_source.htm

thanks - dave


I am not sure you can do this generically with an ODBC connector. If I am
correct, you will have to write database specific routines and call the
connector through a factory. If you have to go this route, I would consider
building on an open/shared source implementation like the Enterprise
Library.


david@[email protected]
Windward Reports -- http://www.WindwardReports.com
me -- http://dave.thielen.com

Cubicle Wars - http://www.windwardreports.com/film.htm
 
Back
Top