GetSchemaTable not working correctly in SQL 2005/ADO.NET 2.0

R

Robert Bouillon

I ran GetSchemaTable on every table in AdventureWorks, and a few tables
came back with bad meta-data.

For example, if you run GetSchemaTable on Production.BillOfMaterials,
BillOfMaterialsID has an IsKey value of false, which is not incorrect.

I know I can use catalog views to get the info I need, but I already
have the code written and working, albeit this bug. Is this a bug in
ADO or something I'm not doing correctly?

Here's a snippet of code.
===========================================================
{...}
try
{
cmd = conn.CreateCommand();
cmd.CommandText = string.Format("SELECT * FROM {0}",tableName);
idr = cmd.ExecuteReader(CommandBehavior.SchemaOnly |
CommandBehavior.KeyInfo);

DataTable dt = idr.GetSchemaTable();
Populate(dt, tableName); //Use the schema data...
idr.Close();
}
{...}
===========================================================

Thanks in advance.

--ROBERT
 
R

Robert Bouillon

For example, if you run GetSchemaTable on Production.BillOfMaterials,
BillOfMaterialsID has an IsKey value of false, which is not incorrect.

Correction -> *...which is not correct.*
 
Top