Well, it appears all is not well with transformations between datetime datatypes with C# and SQL Server. I was having an error occur when executing as stored procedure passing a datetime parameter. Primarily, I was trying to pass an empty or null value to the database and haven't yet found a solid way to do this. Instead, I thought I would trap the minimum datetime value and insert null instead at the SP side. Well, as it turns out, DateTime.MinValue and SqlDateType.MinValue are not equal.
So my next attempt was to set the value to System.Data.SqlTypes.SqlDateTime.MinValue. However, my field is a smalldatetime instead and the min values are not equal. I ended up coding in a DateTime.Parse("1/1/1900") as that is the minimum small date time value.
For future reference, here are the min's:
DateTime.MinValue = 1/1/0001
SqlDateTime.MinValue = 1/1/1753
the min for SmallDateTime = 1/1/1900
I wish they had a SqlSmallDateTime.MinValue (it would make sense).
No comments:
Post a Comment