Link to home
Start Free TrialLog in
Avatar of websss
websssFlag for Kenya

asked on

Datareader - checking for system,indexOutOfRangeException

I have a data reader that has this code

while (dr.Read())
                {
 if (Convert.ToInt16(dr[0]) > 0) {     
                    recordsReturned = 1;
                    }

Open in new window


This works fine if results are returned, but if the data reader has no results, it breaks
I tried using .HasRows, but it always has rows for some reason

Anyway, what code do i need to check for this out of range exception?
ASKER CERTIFIED SOLUTION
Avatar of Daniel Van Der Werken
Daniel Van Der Werken
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial