一个DATETIME2数据类型的转换为datetime数据类型的结果超出范围值 [英] Conversion of a datetime2 data type to a datetime data type results out-of-range value

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

问题描述

我有一个数据表5列,其中一列中填充数据,然后通过一个事务保存到数据库中。

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:

一个DATETIME2数据类型到datetime数据类型的转换导致超出范围的值

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

这意味着,读,我的数据表的类型为 DATETIME2 和我的数据库中的的DateTime ;这是错误的。

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

日期列设置为的DateTime 是这样的:

The date column is set to a DateTime like this:

新的DataColumn(数值指明MyDate,Type.GetType(System.DateTime的))

能否在这个code解决或做一些事情一定要在数据库级别改变?

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?


顺便说一句,以获得正确的方式键入对象的的DataColumn 构造函数是的typeof 关键字,这是快几个数量级。

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天全站免登陆