将datetime2数据类型转换为datetime数据类型会导致超出范围的值 [英] Conversion of a datetime2 data type to a datetime data type results out-of-range value

查看:130
本文介绍了将datetime2数据类型转换为datetime数据类型会导致超出范围的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含5列的数据,其中一行正在填充数据,然后通过事务保存到数据库。



保存时出现错误返回:


将datetime2数据类型转换为datetime数据类型导致超出范围值


这意味着,读取时,我的datatable的类型为$ code> DateTime2 和我的数据库a DateTime ;这是错误的。



日期列设置为 DateTime ,如下所示:



新的DataColumn(myDate,Type.GetType(System.DateTime))



问题



可以在代码中解决这个问题,还是在数据库级别上修改某些内容?

解决方案

你在列中有哪些日期?



适合这种类型的范围?






除此之外,获得 DataColumn 构造函数键入对象是 typeof 关键字,这是更快的数量级



因此,要创建列,您应该写

 新的DataColumn(myDate,typeof(DateTime))


I've got a datatable with 5 columns, where a row is being filled with data then saved to the database via a transaction.

While saving, an error is returned:

The conversion of a datetime2 data type to a datetime data type resulted in an out-of-range value

It implies, as read, that my datatable has a type of DateTime2 and my database a DateTime; that is wrong.

The date column is set to a DateTime like this:

new DataColumn("myDate", Type.GetType("System.DateTime"))

Question

Can this be solved in code or does something have to be changed on a database level?

解决方案

What kind of dates do you have in the column?

Do all of them fit within the range of the type?


As an aside, the correct way to get a Type object for the DataColumn constructor is the typeof keyword, which is orders of magnitude faster.

Therefore, to create the column, you should write

new DataColumn("myDate", typeof(DateTime))

这篇关于将datetime2数据类型转换为datetime数据类型会导致超出范围的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆