June 27, 2009 at 1:42 am
In my application, there is one Datetime field. While saving if the date field is not selected it stores "1/1/1900 12:00:00 AM" in database. I want to store "NULL" [/i] instead. Please help me resolve this problem.
June 27, 2009 at 2:11 am
That is sql default behaviour. Make the column nullable and create a default constraint.
June 27, 2009 at 3:16 am
I have already kept the AllowNulls property of the Date column to True, but still it enters the 1/1/1900 12:00:00 AM in the database.
June 27, 2009 at 3:43 am
1/1/1900 is 0 as a date. It means that either you're explicitly inserting the value 0 or '' into that column, or there's a default of 0 or '' on that column. Check both and ensure that the column is nullable, there's no default on it and you're not explicitly passing 0 or '' to it.
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
June 27, 2009 at 4:02 am
In VB.net/ ASP.net when we use
Dim BDate as Date
its default value is 12:00:00 AM
and while saving if the new date is not assigned to the BDate, then 1/1/1900 12:00:00 AM is stored in the database.
June 28, 2009 at 4:38 am
Cool - so you have identified the cause.
Now you need to change the program so that it inserts a NULL instead - if your variable has not been assigned to.
I'm no VB.NET expert, but using a variable which has not been assigned to seems less than ideal?
Paul
Paul White
SQLPerformance.com
SQLkiwi blog
@SQL_Kiwi
June 28, 2009 at 5:40 am
aniket (6/27/2009)
and while saving if the new date is not assigned to the BDate, then 1/1/1900 12:00:00 AM is stored in the database.
So how are you doing the save to database?
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply