I am trying to figure out how to check if my SqlDataReader
is null or has no rows (meaning the reservation does not exist) and then display a messagebox. For so
For some reason when I debug once it hits the
while dr.Read()
Code it steps out if it does not have a return result
I think what you're seeing here is that SQLDataReader.Read()
returns false
if there is not a next, or in this case a first record to read.
As others have responded, use the HasRows
property to determine if you have any rows in the result set. Depending on what you need to accomplish, you may want to take advantage of the fact that Read()
indeed returns false
the first time its called for an empty result set.