DateTime.MinValue and SqlDateTime overflow

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

    Here is what you can do. Though there are lot many ways to achieve it.

    DateTime? d = null;    
    if (txtBirthDate.Text == string.Empty)
        objinfo.BirthDate = d;
    else
        objinfo.BirthDate =  DateTime.Parse(txtBirthDate.Text);
    

    Note: This will work only if your database datetime column is Allow Null. Else you can define a standard minimum value for DateTime d.

提交回复
热议问题