DateTime and null values

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.
 
G

Guest

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top