שתף באמצעות


Null DateTime Value in DataRow

Question

Friday, July 15, 2011 3:19 PM

I am having trouble setting a datetime column in a datarow to null or MinValue and updating the database row using a DataAdapter update command. 

In one scenario, if the value in a text box is not a valid data, I set the value in the datarow = DateTime.MinValue.  The value returned by MinValue is #12:00:00 AM#.  An error is thrown on the Update command  "SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM."

In another scenario, an error is not thrown but the DateTime value on the row is not changed.

The database column allows nulls and I can set the value to null using a SQL update command.  Can someone shed some light on this for me?  Thanks and have a good weekend.

All replies (5)

Friday, July 15, 2011 4:04 PM ✅Answered | 1 vote

Yea that is the date which is taken as calender start in SQL Server, it is the aprox date where in all the colonies of the British Empire the Gregorian Calendar started.

If you want an earlier SQL server datetime for SQL Server 2008 than use the DateTime2 in that database

Be aware Null Alowed in a DataBase server does not fill an Null likewise Net.

If you want to test in Net for the same value type use

TheReturnedDateTime Is DBNull.Value 

Success
Cor


Friday, July 15, 2011 5:54 PM ✅Answered | 1 vote

You can use SqlDateTime.MinValue if that's any help, otherwise setting the database value to null would be more accurate.

http://stackoverflow.com/questions/649426/how-can-i-pass-a-null-value-for-date-in-vb-net-to-sql-stored-procedure

--
Andrew


Friday, July 15, 2011 5:59 PM

Cor - I didn't believe at first (sorry man, nothing personal) so I had to look it up for myself.  Here's a good link that talks about it (one of many out there on teh webs):

http://stackoverflow.com/questions/3310569/what-is-the-significance-of-1-1-1753-in-sql-server

 

This too - funny and interesting:  http://www.csd.uwo.ca/staff/magi/personal/humour/Computer_Audience/%27cal%209%201752%27%20explained.html

 


Friday, July 15, 2011 7:41 PM

Hi Dig Boy, 

Yea that is the problem with us from the Atlantic atmosphere; Australia and New Sealand included by the way.

We assume that everybody in the world is thinking in our way of thinking. 

In our Atlantic view of the world; we think often that the way we think is the only view of the world.

Probably in many cases we are wrong.

:-) 

I've the idea mostly we don't recognise that.

:-)

These forums shows us a little bit the real world, where everybody in the world (I hope) tells their view; which makes me happy.

:-)

 

 

Success
Cor


Monday, July 18, 2011 5:58 AM

Hello Dave,

Would you mind letting us know the result of above suggestions? If you have any concerns, please feel free to follow up.

Have a nice day.

Best regards

Liliane Teng [MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.