错误:SqlDateTime 溢出。必须介于 1/1/1753 12:00:00 AM 和 12/31/9999 11:59:59 PM 之间

SqlDateTime 溢出。必须介于 1/1/1753 12:00:00 AM 和 12/31/9999 11:59:59 PM 之间

 

 如果日期字段为null时,默认的更新是1/1/0001,这样便会出错

 所以在我们想要不输入时间的时候,可以通过数据库默认值的方式(允许为空值)或者存储一个不会使用到的时间存储就可以了,

例如存储最小值 SqlDateTime.MinValue.Value 同时我们在也可以使用日期前跟 SqlDateTime.MinValue.Value比较,这样减少一些误操作,流程更严谨些.

 

        public bool InsertApply()
{
SendApply Apply = new SendApply();
Apply.CustomerID = this.CustomerID;
Apply.ConfirmSend = this.ConfirmSend;
//Apply.TimeForSendOver = Convert.ToDateTime("2011-1-1");
//Apply.TimeForThis = DateTime.Now;
if (RuleTimeRangeID == 0)
{
this.InsertTimeRule();
}
Apply.RuleTimeRangeID = this.RuleTimeRangeID;
Apply.SrcNumbers = this.Numbers;
Apply.TimeForBeginSend = this.TimeForBegingSend;

SendApplyService SendApplyS = new SendApplyService();

if (SendApplyS.Insert(Apply) > 0)
return true;
else
return false;
}

错误:SqlDateTime 溢出。必须介于 1/1/1753 12:00:00 AM 和 12/31/9999 11:59:59 PM 之间

 

你可能感兴趣的:(DateTime)