MasterRacker
New member
I'm continuing to fight the good fight with dealing with a SQL DateTime that allows nulls and the fact that .NET DateTimes do not. In the example below, obj.DateMember is a .NET DateTime that either contains a valid date or DateTime.MinValue substituted for a null date.
This all works fine for reading nullable dates out of SQL. How do I feed a null back into SQL though?
I'm assuming there's some kind of implicit conversion going on from a .NET DateTime to a SQL DateTime when I'm assigning the value. I can't simply assign System.DBNull because that's a class instead of an object, but I'm having a brain death episode on how to send that null back in.
Jeff
[purple]It's never too early to begin preparing for [/purple]International Talk Like a Pirate Day
"The software I buy sucks, The software I write sucks. It's time to give up and have a beer..." - Me
This all works fine for reading nullable dates out of SQL. How do I feed a null back into SQL though?
Code:
updateCommand.Parameters.Add(new System.Data.SqlClient.SqlParameter("@DateMember", System.Data.SqlDbType.DateTime, 8, "DateColumn"));
.
.
if (obj.DateMember == DateTime.MinValue)
{
updateCommand.Parameters["@DateMember"].Value = ?????;
}
else
{
updateCommand.Parameters["@DateMember"].Value = obj.DateMember;
}
I'm assuming there's some kind of implicit conversion going on from a .NET DateTime to a SQL DateTime when I'm assigning the value. I can't simply assign System.DBNull because that's a class instead of an object, but I'm having a brain death episode on how to send that null back in.
Jeff
[purple]It's never too early to begin preparing for [/purple]International Talk Like a Pirate Day
"The software I buy sucks, The software I write sucks. It's time to give up and have a beer..." - Me