Monday, March 19, 2012

DataReader returns different results when there are null fields

If I query sql server I get 10 results. But when I use if (myReader.Read()) I get only 7 results. I found that there was a Null field in the DB. I changed it and it worked.
The problem is I don't want to touch the database and set all null fields. There must be a way to get all results including the Null using sqlDataReader so that if (myReader.Read()) is used it does the right comparison.

// This code is called 10 times with a select * from where item="xxx"
P21Conn.Open();

SqlDataReader myReader = cmd.ExecuteReader();

if (myReader.Read()) {

thanks
Rodin your select or sproc, use ISNULL or COALESCE around the columns that have null values.

cs|||Thank you

I did that and now it works perferct

Rod