I am populating my object with results from a database via a sqlDataReader like so:
foreach (DataRow dr in dt.Rows)
{
wt = new WorkTasksDto
{
CompletedBy = dr.IsNull("CompletedBy") ? (DateTime?)null : (DateTime?)dr["CompletedBy"]
};
}
As you can see im checking for a DbNUll, but one of my records for my date field is blank. Not null, just like an empty varchar field and when I try to do my DateTime cast, I get an invalid cast error.
How do I check for a blank field as well as a DbNull field?
Not very clean but this seems to work.