Home All Groups Group Topic Archive Search About

asp.net datareader+sql server+null fields=error

Author
15 Sep 2005 6:28 PM
the friendly display name
Following problem:

I try to select records where a field is null.

i.e.:

MyCommandGeneric.CommandText = "select A, b from object where C is null";

MyDataReader = MyCommandGeneric.ExecuteReader();

If I try now to access the values (string bla = MyDataReader["A"]), I am
getting the error, that datareader can't read, when there is no data.

But there is data!

I tried to query the sql server directly with the above query, and it gives
a record.

Author
15 Sep 2005 6:38 PM
Alejandro Mesa
I think you have to execute read method before accessing the data.

SqlDataReader Class http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemdatasqlclientsqldatareaderclasstopic.asp


AMB

Show quote
"the friendly display name" wrote:

> Following problem:
>
> I try to select records where a field is null.
>
> i.e.:
>
> MyCommandGeneric.CommandText = "select A, b from object where C is null";
>
> MyDataReader = MyCommandGeneric.ExecuteReader();
>
> If I try now to access the values (string bla = MyDataReader["A"]), I am
> getting the error, that datareader can't read, when there is no data.
>
> But there is data!
>
> I tried to query the sql server directly with the above query, and it gives
> a record.
Author
15 Sep 2005 6:46 PM
the friendly display name
Oh, good god.

Of course! Now it works.

Show quote
"Alejandro Mesa" wrote:

> I think you have to execute read method before accessing the data.
>
> SqlDataReader Class
> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemdatasqlclientsqldatareaderclasstopic.asp
>
>
> AMB
>
> "the friendly display name" wrote:
>
> > Following problem:
> >
> > I try to select records where a field is null.
> >
> > i.e.:
> >
> > MyCommandGeneric.CommandText = "select A, b from object where C is null";
> >
> > MyDataReader = MyCommandGeneric.ExecuteReader();
> >
> > If I try now to access the values (string bla = MyDataReader["A"]), I am
> > getting the error, that datareader can't read, when there is no data.
> >
> > But there is data!
> >
> > I tried to query the sql server directly with the above query, and it gives
> > a record.

AddThis Social Bookmark Button