I have a data table that contains a "CreateDate" and an "UpdateDate" columns. I am trying to find the smallest CreateDate and largest UpdateDate. It is not difficult but columns can contain NULL (or DBNull) and this is tripping me. I was using the following:
DateTime dtMin = DateTime.MaxValue;
DateTime dtMax = DateTime.MinValue;
foreach(DataRow dr in dt.Rows)
{
DateTime dtCreateDate = dr.Field<DateTime>("CreateDate");
DateTime dtUpdateDate = dr.Field<DateTime>("UpdateDate");
dtMin = dtMin > dtCreateDate ? dtCreateDate : dtMin;
dtMax = dtMax > dtUpdateDate ? dtMax : dtUpdateDate;
}
Until I hit a row with a NULL date.