all groups > dotnet ado.net > june 2006 >
You're in the

dotnet ado.net

group:

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



GetSchemaTable not working correctly in SQL 2005/ADO.NET 2.0 Robert Bouillon
6/30/2006 2:54:39 PM
dotnet ado.net: 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
Re: GetSchemaTable not working correctly in SQL 2005/ADO.NET 2.0 Robert Bouillon
6/30/2006 2:58:24 PM
[quoted text, click to view]

Correction -> *...which is not correct.*
AddThis Social Bookmark Button