日期时间字段溢出与IBM数据服务器客户v9.7fp5 [英] Datetime field overflow with IBM Data Server Client v9.7fp5

查看:737
本文介绍了日期时间字段溢出与IBM数据服务器客户v9.7fp5的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用的EntityFramework 4.1版和IBM数据服务器客户机 v9.7fp5 ,DB首先产生code基于一个pre定义的DB2表,有DATE列。在code生成过程中的DB2 DATE列映射到.NET DateTime数据类型。

Using EntityFramework v4.1 and IBM Data Server Client v9.7fp5, DB first generated code based on a pre-defined DB2 table which has DATE columns. The DB2 DATE columns are mapped to .NET DateTime data types during the code generation.

当试图插入行,收到以下错误

When attempting to INSERT a row, receive the following error

错误[22008] [IBM] CLI0114E日期时间字段溢出。 SQLSTATE = 22008

ERROR [22008] [IBM] CLI0114E Datetime field overflow. SQLSTATE=22008

这是有道理的,因为.NET没有日期数据类型,只是DATETIME和属性将有更多的数据,那么DB2 DATE列期望的那样。

which makes sense, since .NET does not have a DATE data type, just DATETIME and that attribute would have more data then the DB2 DATE column would expect.

的问题是

  1. 为什么不.NET基code自动转换使用ToShortDateString(),并提供DB2什么期待?

  1. why doesn't the .NET base code automatically convert using ToShortDateString() and provide DB2 what it is expecting?

什么办法可以用来覆盖.NET基础逻辑和转换中的应用code值之前.NET提交SQL事务到DB2?

what approaches could be used to override the .NET base logic and convert the value within application code before .NET submits the SQL transaction to DB2?

任何帮助或意见,将AP preciated。谢谢!

Any assistance or feedback would be appreciated. Thanks!

推荐答案

阅读日期时间数据类型转换(ODBC)。它定义了各种规则的数据类型转换。一个是如下 - 。SQLSTATE 22008

Read datetime Data Type Conversions (ODBC). It defines various rules in datatype conversions. One is listed below - SQLSTATE 22008.

如果从C转换为SQL时发生秒或分数秒截断,与SQLSTATE 22008和消息日期时间字段溢出产生的诊断记录。

If truncation of seconds or fractional seconds occurs when converting from C to SQL, a diagnostic record is generated with SQLSTATE 22008 and the message "Datetime field overflow".

这里的关键是要确保没有发生任何以秒/秒的小数

The key point here is to make sure that there happens no truncation in seconds/fractional seconds

DATE数据类型

如果DB2数据库列 DATE 的数据类型,创建变量:

If the DB2 database column is DATE datatype, create your variable as listed below:

new DateTime(2012,3,4); //No time part

timestamp数据类型

如果DB2数据库列 TIMESTAMP 的数据类型,删除毫秒部分:

If the DB2 database column is TIMESTAMP datatype, remove fraction of milliseconds:

dateTime = new DateTime(dateTime.Ticks - (dateTime.Ticks % TimeSpan.TicksPerSecond),dateTime.Kind);

参考

  1. <一个href="http://stackoverflow.com/questions/1004698/how-to-truncate-milliseconds-off-of-a-net-datetime">How截断毫秒掀起了.NET的DateTime
  2. 为什么的SQL Server失去毫秒?
  1. How to truncate milliseconds off of a .NET DateTime
  2. Why is SQL Server losing a millisecond?

DB2 INSERT日期和TIMESTAMP

如果您在DB2中直接使用SQL语句插入,

If you inserting with direct SQL statement in DB2,

对于像'2012-12-17-16.53.57.285754'时间戳使用的格式

for TimeStamp use format like '2012-12-17-16.53.57.285754'

对于像CAST日期使用格式('2012年12月10日'AS DATE)

for DATE use format like CAST ('2012-12-10' AS DATE)

这篇关于日期时间字段溢出与IBM数据服务器客户v9.7fp5的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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