How can I check for a NULL
value in an open MySqlDataReader
?
The following doesn't work; it's always hitting the else
:
if (rdr.GetString("timeOut") == null)
{
queryResult.Egresstime = "Logged in";
}
else
{
queryResult.Egresstime = rdr.GetString("timeOut");
}
rdr.IsDbNull(int i)
only accepts a column number, not name.
or
if(rdr.GetString("timeOut") == DBNull.Value)null
is not the same asDBNull
I am sorry, wrong answer, Sam B is right. I mistook this for
DataRow
stuff.SqlDataReader does have strongly typed
GetString()
and providesIsDBNull(int column)
for this case.