IBM Data Server Client v9.7fp5 的日期时间字段溢出 [英] Datetime field overflow with IBM Data Server Client v9.7fp5

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

问题描述

使用 EntityFramework v4.1 和 IBM Data Server Client v9.7fp5,DB 首先基于具有 DATE 列的预定义 DB2 表生成代码.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.

尝试INSERT一行时,收到以下错误

When attempting to INSERT a row, receive the following error

ERROR [22008] [IBM] CLI0114E 日期时间字段溢出.SQLSTATE=22008

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

这是有道理的,因为 .NET 没有 DATE 数据类型,只有 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 基本代码不使用 ToShortDateString() 自动转换并为 DB2 提供它所期望的?

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

在 .NET 将 SQL 事务提交给 DB2 之前,可以使用哪些方法来覆盖 .NET 基本逻辑并转换应用程序代码中的值?

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?

我们将不胜感激任何帮助或反馈.谢谢!

Any assistance or feedback would be appreciated. Thanks!

推荐答案

阅读datetime 数据类型转换 (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".

这里的关键是确保在秒/小数秒内没有发生truncation

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

日期数据类型

如果 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. 如何截断 .NET DateTime 的毫秒数
  2. 为什么 SQL Server 会丢失一毫秒?

<小时>

DATE 和 TIMESTAMP 的 DB2 INSERT

如果您在 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'

对于 DATE,使用格式如 CAST ('2012-12-10' AS DATE)

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

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

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