How does GetSchema get foreign key constraints?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

The GetSchema documentation hurts, specifically:
"Understanding the Provider-Specific Schema Collections" at
http://msdn2.microsoft.com/en-us/library/ms254969(VS.80).aspx

I'm trying to create a DataSet that matches an SQL Server database, and I've
gotten close.

I'm calling SqlConnection's GetSchema( "Tables"), and then for each table
name, I'm doing:

sqlDataAdapter = new SqlDataAdapter( "SELECT * FROM " + dataTableName,
sqlConnection);
sqlDataAdapter.FillSchema( dataSet, SchemaType.Mapped, dataTableName);

Doing so initializes the data tables of the data set, including primary
keys. What remains to be done is to create the foreign key constraints.

Calling GetSchema( "ForeignKeys") returns the following columns:
CONSTRAINT_CATALOG
CONSTRAINT_SCHEMA
CONSTRAINT_NAME
TABLE_CATALOG
TABLE_SCHEMA
TABLE_NAME
CONSTRAINT_TYPE
IS_DEFERRABLE
INITIALLY_DEFERRED

What I expected to see was a local table name, the local field of the
foreign key, the referenced table name, and the primary key field of the
referenced table. Where is that?

Thanks in advance.
 
Thanks.

How lame of Microsoft not to have GetSchema() return foreign keys,
especially since it returns a collection called "ForeignKeys". What value is
that collection supposed to serve, if it doesn't show the table and PK to
which it's linked?
 
Back
Top