DateTime and null values

  • Thread starter Thread starter steve gibson
  • Start date Start date
S

steve gibson

I am trying to enter null values into a database using
DateTime values. Where the string is empty I need to null
the value in the database.

if (dataAvailActual.ToString().Trim()!=string.Empty)
r.DATE_ACTUAL= System.DateTime.Parse(dataAvailActual);
else
r.PUBLICATION_DATE_ACTUAL= null;

The compiler gives me :
Cannot convert null to 'System.DateTime' because it is a
value type.
DBNull does not work either.
 
Hi steve,

DateTime type is a value type (structure) so it cannot be nullable.

The DataRow object has fields of object's type so you
can set their values to DBNull.Value as a DB NULL.

If you've got property of DateTime type then you cannot set it
to other type than DateTime.

HTH
Marcin
 
Back
Top