DateTime.MinValue and SqlDateTime overflow

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

    I am using this function to tryparse

    public static bool TryParseSqlDateTime(string someval, DateTimeFormatInfo dateTimeFormats, out DateTime tryDate)
        {
            bool valid = false;
            tryDate = (DateTime)System.Data.SqlTypes.SqlDateTime.MinValue;
            System.Data.SqlTypes.SqlDateTime sdt;
            if (DateTime.TryParse(someval, dateTimeFormats, DateTimeStyles.None, out tryDate))
            {
                try
                {
                    sdt = new System.Data.SqlTypes.SqlDateTime(tryDate);
                    valid = true;
                }
                catch (System.Data.SqlTypes.SqlTypeException ex)
                {
    
                }
            }
    
            return valid;
        }
    

提交回复
热议问题