In this situation, I like to represent columns of a null database with a reference type (row for varchar) or Nullable wrapped value type (DateTime?). Thus, you more accurately represent the database schema in your program.
It also allows you to more clearly write the conversion logic in the format:
DateTime? fdate = datareader["fdate"] as DateTime?;
This action will not be performed if the result of the datareader is DbNull, and fdate will be set by default (DateTime?), Which is null. At this point, you can get your real desired value by checking if the value is nullable or not (fdate.HasValue), and if not, use your default DateTime.Today.
medkg15
source share