|
database
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
asp.net datareader+sql server+null fields=errorFollowing 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. 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. 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. |
|||||||||||||||||||||||