Eliminating "1/1/1900" in datetime fields....

asp.net , csharp , db , sql server India
  • 6 years ago

    when storing a record all the the EMPTY value of datetime field are storing as "1/1/1900". How can we avoid this and store "NULL" value while user insert or update a record?
    ( i inserted the record via ASP.NET with C# )

  • 6 years ago

    If the database is set up to allow nulls in the datetime field then, depending upon how you set up the insert statement (inline, stored proc, etc):

    you simply need to set the parameter value going through to Sql to be "DbNull.Value" or if inline, use "null" as the value - as in "insert xyz(dt) values (null)"

    HTH,

    Joe 

  • 6 years ago

    i m inputting from ASP.NET with C# coding to SQL server (version 2003, 1.1 framework).

    when i insert or update this 1/1/1900 is getting inserted to the database....

    is there any trigger to eliminate this problem? (i.e.. while inserting or updating to a particular table, the trigger should execute and insert the NULL value to the DATETIME fields which contains 1/1/1900)

  • 6 years ago

    To be fair, yes, a trigger would work without problem - but only if the column allows nulls. Other than that, if yiou want to do it in the application rather than the database, you'd have to check the datetime value in the code and do as I suggested in my previous post.

    Codes always helpful here.

    Joe 

  • 6 years ago

    sorry i didnt analyse about this my friend.

    but the thing is "DATETIME field will accept NULL"

  • 6 years ago

    Ok,

    So lets see the code you're working with.

    Joe 

  • 6 years ago

    sorry my friend.this trigger concept is just an idea of my TEAM LEADER. i m not that much strong in SQL... do the favour plz

  • 6 years ago

    Have a look here: http://msdn2.microsoft.com/en-us/library/aa213995(SQL.80).aspx

    Joe 

  • 6 years ago

    IS THERE ANYONE HERE TO GIVE ME CODING TO REMOVE 1/1/1900 in database and to insert NULL???????????????????????????????????

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“A computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are, in short, a perfect match” - Bill Bryson