Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

More DateTime 'Fun' 1

Status
Not open for further replies.

MasterRacker

New member
Oct 13, 1999
3,343
0
0
US
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?

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.

[sub]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[/sub]
 
Can you set it to DBNull.Value? System.DBNull is the class, but DBNull.Value is the actual value.

bjordan
 
That's what I needed. It's always obvious, once you see it. Thanks.

[sub]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[/sub]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top