DateTime.MinValue and SqlDateTime overflow

前端 未结 10 660
北恋
北恋 2021-02-01 00:44

I don\'t want to validate txtBirthDate so I want to pass DateTime.MinValue in database.

My code:

 if (txtBirthDate.Text == st         


        
10条回答
  •  不要未来只要你来
    2021-02-01 01:04

    Basically, don't use DateTime.MinValue to represent a missing value. You can't use DateTime.MinValue in a SQL Server DateTime field, as SQL Server has a minimum value of the start of 1753.

    Instead, make your BirthDate property a Nullable (aka DateTime?), and set it to null when you don't have a value. Also make sure your database field is nullable. Then you just need to make sure that that null ends up as a NULL value in the database. Exactly how you do that will depend on your data access, which you haven't told us anything about.

提交回复
热议问题