问题描述

在平时使用代码操作SQL Server数据库时,会遇到给日期格式的字段赋值,然后插入或者更新到数据库中等。
平时使用的日期都是比较靠近现在的时间,所以一般不会遇到问题。但是有时候,比如在C#中的DateTime类中

DateTime.MinValue1/1/0001 12:00:00 AM最小值是DateTime的默认值DateTime.MaxValue12/31/9999 11:59:59 AM

如果给某个字段赋值的值,使用的是DateTime的默认值,那么在操作数据库时,就会出现下面的错误:
The conversion of a datetime2 data type to a datetime data type resulted in an out-of-range value.
The statement has been terminated.

如果是通过string 赋值,会遇到下面的问题:
The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.
The statement has been terminated.

大致意思就是:这个值不在数据库字段类型的范围内。

解决思路

在msdn上找到了SQL Server的datetime的相关文档

datetime(T-SQL)

通过官网资料,就能知道,该字段用了什么数据格式,它的范围就确定了,后面的操作,应该在要求的范围内,就可以解决问题。

总结如下

datetime 的范围是:1753-01-01 00:00:00 到 9999-12-31 23:59:59.997
datetime2 的范围是:0001-01-01 00:00:00 到 9999-12-31 23:59:59.9999999
date 的范围是:0001-01-01 到 9999-12-31
smalldatetime 的范围是:1900-01-01 00:00:00 到 2079-06-06 23:59:59

解决The conversion of a datetime2 data type to a datetime data type resulted in an out-of-range value相关推荐

  1. The conversion of a varchar data type to a datetime data type resulted in an out-of-range value

    刚刚有在程序中,传递一个空值至MS SQL Server数据库,这个值的数据类型为DATETIME 执行时,它却发生了如标题提示的异常: The conversion of a varchar dat ...

  2. 成功解决IndexError: arrays used as indices must be of integer (or boolean) type

    成功解决IndexError: arrays used as indices must be of integer (or boolean) type 目录 解决问题 解决思路 解决方法 解决问题 I ...

  3. 成功解决ValueError: Expected 2D array, got 1D array instead: Reshape your data either using array.reshap

    成功解决ValueError: Expected 2D array, got 1D array instead: Reshape your data either using array.reshap ...

  4. Input type (torch.FloatTensor) and weight type (torch.cuda.FloatTensor) should be the same(解决)

    问题描述 在使用pytorch训练经典的MNIST数据集时,运行时,出现了以下的问题: Input type (torch.FloatTensor) and weight type (torch.cu ...

  5. 成功解决 RecoveryYour PC/Device needs to be repairedThe Boot c onfiguration Data for your PC is missin

    成功解决 RecoveryYour PC/Device needs to be repairedThe Boot c onfiguration Data for your PC is missin 目 ...

  6. Data too long for column ‘data‘ at row 1以及设置成longblob造成的乱码解决。node-mysql

    Data too long for column 'data' at row 1以及设置成longblob造成的乱码解决 前几天一个月薪35k的兄弟,给我推了一个人工智能学习网站,看了一段时间挺有意思 ...

  7. 解决:RuntimeError: Expected object of scalar type Int but got scalar type Double

    问题描述: 最近在写使用神经网络预测的代码,在更换导入的数据后,原本的loss函数(如下所示)报错RuntimeError: Expected object of scalar type Int bu ...

  8. 小程序开发报错 使用wx.reLaunch跳转报错 Expected updated data but get first rendering data如何解决 ???

    页面跳转 使用wx.reLaunch({url: '/pages/list-item/list-item'}) 报错 VM15485:5 Expected updated data but get f ...

  9. 解决微信返回码为40113,错误信息errmsg:unsupported file type

    解决微信返回码为40113,错误信息"errmsg":"unsupported file type" // PHP代码 $file_name = md5(mic ...

最新文章

  1. Python 入门篇-用Notepad++编写出第一个python程序
  2. ie,火狐下滚动条的问题
  3. Xamarin效果第三篇之手机底部弹窗
  4. 模拟电路--单电源差分运算放大电路方案
  5. Array.prototype.slice.call()方法详解
  6. android自助终端界面_滨州市人社自助服务终端上线新功能可查询个人在山东省所有地市的参保信息...
  7. java读取一个应用程序_Java IO – 在写入其他应用程序时读取一个大文件
  8. mysql统计信息表行数不准确_mysql SQL调优-统计信息不准的原因
  9. mysql解决端口占用
  10. 金九银十BAT互联网企业涨薪必备知识点:Jvm性能调优实战
  11. CANape XCP on CAN工程创建
  12. 输入银行卡号匹配银行名称
  13. android 小米读写权限,Android 小米手机的权限问题
  14. 汉字编码:区位码、国标码、机内码
  15. 什么是智能标签?DevExpress WPF控件这份入门指南请查收
  16. 加拿大高中计算机课,全面解析加拿大高中课程
  17. 【Centos7进入root权限是报错:sudo: /etc/sudo.conf is owned by uid 1000, should be 0】
  18. 临时执法卡点的设置原理与选址分析
  19. java多态的三种表现形式
  20. 【转载】新韭菜日记39--20190318 ----最近反思 学习分析财务

热门文章

  1. nodejs+vue+elementui图书在线阅读网站系统express
  2. 基于网页在线图书小说电子书阅读系统 毕业设计毕设源码毕业论文开题报告参考(2)网站和用户功能
  3. ubuntu安装redis并使用
  4. CoinCola可盈可乐研究院2月报 | 加密货币集体上涨
  5. 小猿圈IT自学分享-自学编程需要克服的困难
  6. Python基础—简介、变量、运算符
  7. 安装与配置VMware虚拟机 https://www.vmware.com/cn/products/workstation-pro/workstation-pro-evaluation.html
  8. 0206.BFPRT在一大堆数中求其前k大或前k小的问题,简称TOP-K问题(左神算法基础班源码)
  9. 兼容Android 11 相机拍照,从相册中选择,裁剪图片
  10. JAVA的sdn控制器,软件定义网络基础---SDN控制平面