zoukankan      html  css  js  c++  java
  • SqlDateTime overflow / SqlDateTime 溢出

    Error - SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM
    SqlDateTime 溢出。必须介于 1/1/1753 12:00:00 AM 和 12/31/9999 11:59:59 PM之间

    原因

    使用C# insert或者update数据库时,datetime字段值为空默认插入C# 0001年01月01日 造成sql server datetime类型溢出。

    C#中DateTime类型范围

    DateTime.MinValue = 1/1/0001 12:00:00 AM
    DateTime.MaxValue = 23:59:59.9999999, December 31, 9999, 
                        exactly one 100-nanosecond tick 
                        before 00:00:00, January 1, 10000
    

    Sql Server中Datetime类型范围

    between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM
    

    解决办法

    插入或更新DB时对DateTime类型字段进行判断,如果是null或者小于Sql server 最小值 1/1/1753 ,手动赋值 为 DateTime.MinValue

    if(model.SubmitDateTime == null || model.SubmitDateTime == DateTime.MinValue)
    {
    	model.SubmitDateTime = new DateTime(1900, 1, 1);
    }
    
  • 相关阅读:
    第几天?
    农历02__资料
    农历01
    VC6_预编译头
    QWebEngine_C++_交互
    Qt570_CentOS64x64_02
    Qt570_CentOS64x64_01
    QWebEngineView_CssVariables
    Windows__书
    Win7SDK
  • 原文地址:https://www.cnblogs.com/fanyong/p/3930243.html
Copyright © 2011-2022 走看看