M
me
I am using a sqldatareader with this command:
select max(id) from x
If there is no rows in table x then using
sqldatareader.read() still return true as if
there is a row, which means this code breaks:
if (sqldatareader.read()) {
... = sqldatareader.GetInt32(0); // field 0 is null!?
}
All the examples i have seen on ms website and
in books dont take any precautions for empty
tables. Right now i am doing this:
if (sqldatareader.read() && !sqldatareader.IsDBNull(0)) {
... = sqldatareader.GetInt32(0);
}
It seems clumsy. I am doing somthing wrong here?
select max(id) from x
If there is no rows in table x then using
sqldatareader.read() still return true as if
there is a row, which means this code breaks:
if (sqldatareader.read()) {
... = sqldatareader.GetInt32(0); // field 0 is null!?
}
All the examples i have seen on ms website and
in books dont take any precautions for empty
tables. Right now i am doing this:
if (sqldatareader.read() && !sqldatareader.IsDBNull(0)) {
... = sqldatareader.GetInt32(0);
}
It seems clumsy. I am doing somthing wrong here?