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

查看:42
本文介绍了将 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.

保存时,返回错误:

将 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:

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

问题

这可以用代码解决还是必须在数据库级别进行更改?

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

推荐答案

如果您没有为 DateTime 字段赋值,而该字段没有赋值,则可能会发生这种情况接受 NULL 值.

This can happen if you do not assign a value to a DateTime field when the field does not accept NULL values.

那为我修好了!

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

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