Proper handling of dbnulls in reading values

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am trying to read in values from a table. When a value is null in the
table what is the proper way to handle it.

ex.
Owed.DatePaid = Convert.ToDate(row("DatePaid"))

for some rows DatePaid in the table could be null.
 
Bill, I use the following general routine when dealing with a datareader. If
you are working with a strongly typed report, you will find a
row.Is<fieldname>Null() method generated for you...Chuck

private string GetDBDateString(string fieldname)
{
int index = dr.GetOrdinal(fieldname);
if (dr.IsDBNull(index))
return "";
else
return dr.GetDateTime(index).ToShortDateString();
}
 
Back
Top