Status of Date Variable

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

Guest

This is for a Win form.

How do I check if the date variable is null?

DateTime dtDOB = (DateTime) dgSportsman[rowNum, 8];
 
If that's from the database you might want.

if(dgSportsman[rowNum], 8 != DBNull.Value)
{

}

Mel Weaver said:
if (dtDOB == null)
{
}
Mike L said:
This is for a Win form.

How do I check if the date variable is null?

DateTime dtDOB = (DateTime) dgSportsman[rowNum, 8];
 
Mike L said:
This is for a Win form.

How do I check if the date variable is null?

DateTime dtDOB = (DateTime) dgSportsman[rowNum, 8];

It can't be. There's no concept of a null DateTime in C# 1.1. (There is
in 2.0 - or rather, there's the concept of a null Nullable<DateTime>.

However, if you want to find out whether a value from a database is
null, that's a different matter - you should be using DbNull. For
instance:

if (dgSportsman[rowNum, 8] is DbNull)
{
...
}
 
Back
Top