DateTime.MinValue and SqlDateTime overflow

前端 未结 10 551
北恋
北恋 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:00

    Simply put, don't use DateTime.MinVaue as a default value.

    There are a couple of different MinValues out there, depending which environment you are in.

    I once had a project, where I was implementing a Windows CE project, I was using the Framework's DateTime.MinValue (year 0001), the database MinValue (1753) and a UI control DateTimePicker (i think it was 1970). So there were at least 3 different MinValues that were leading to strange behavior and unexpected results. (And I believe that there was even a fourth (!) version, I just do not recall where it came from.).

    Use a nullable database field and change your value into a Nullable instead. Where there is no valid value in your code, there should not be a value in the database as well. :-)

提交回复
热议问题