Home All Groups Group Topic Archive Search About

ADO.Net 2.0 ; SqlDataReader.GetSchemaTable broken?

Author
1 Mar 2006 6:11 PM
ajj3085
Hi all,

I'm using the GetSchemaTable method on a data reader to determine
information about the table itself.  One of the DataRow's items is
supposed to include IsKey, which tells me if the column is part of the
primary key or not.

I have a simple table with an Int identity as the primary key, but
IsKey is returning a null value..neither true or false.  Is this a bug
in the framework? IsIdentity does return correctly as do most of the
other properties i've examined.

Thanks
Andy

Author
1 Mar 2006 7:01 PM
Kerry Moorman
Andy,

This works for me in ADO.Net 1.1:

rdr = cmd.ExecuteReader(CommandBehavior.SchemaOnly Or CommandBehavior.KeyInfo)

Kerry Moorman


Show quote
"ajj3***@alum.rit.edu" wrote:

> Hi all,
>
> I'm using the GetSchemaTable method on a data reader to determine
> information about the table itself.  One of the DataRow's items is
> supposed to include IsKey, which tells me if the column is part of the
> primary key or not.
>
> I have a simple table with an Int identity as the primary key, but
> IsKey is returning a null value..neither true or false.  Is this a bug
> in the framework? IsIdentity does return correctly as do most of the
> other properties i've examined.
>
> Thanks
> Andy
>
>
Author
6 Mar 2006 8:46 PM
David Sceppa [MSFT]
Kerry is correct.  You need to include KeyInfo in the CommandBehavior
specified when calling ExecuteReader.  Otherwise, key information is not
included with the resultset.

     I hope this information proves helpful.

David Sceppa
Microsoft
This posting is provided "AS IS" with no warranties,
and confers no rights.  You assume all risk for your use.
© 2006 Microsoft Corporation.  All rights reserved.
Author
7 Mar 2006 3:27 PM
Andy
David,

Thanks for the response; I'll give it a shot.

FYI, Kerry's response never appeared for me under this thread..weird.

Andy
Author
8 Mar 2006 3:46 PM
David Sceppa [MSFT]
No problem.  And it's definitely odd that Kerry's reply didn't show up
as part of the thread.  Just so Kerry gets proper credit/kudos, here's that
post:

> Andy,

> This works for me in ADO.Net 1.1:

> rdr = cmd.ExecuteReader(CommandBehavior.SchemaOnly Or
CommandBehavior.KeyInfo)

> Kerry Moorman

David Sceppa
Microsoft
This posting is provided "AS IS" with no warranties,
and confers no rights.  You assume all risk for your use.
© 2006 Microsoft Corporation.  All rights reserved.

AddThis Social Bookmark Button