带有.Net的DB2时间字段 [英] DB2 Time fields with .Net

查看:60
本文介绍了带有.Net的DB2时间字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在DB2时间字段usinc C#和IBM托管的

DB2数据提供程序中存储时间。我得到的错误是SQL0181N,字符串

表示日期时间值超出范围。


我尝试过使用DateTime .TimeOfDay属性,

DateTime.TimeOfDay.Ticks属性,DateTime对象,以及尽可能多的不同

字符串表示,因为我可以提出并且每次我得到同样

错误。


任何想法都会受到赞赏。


谢谢

-

Dale Preston

MCAD C#

MCSE,MCDBA

I am trying to store a time in a DB2 time field usinc C# and the IBM managed
DB2 data provider. The error I am getting is SQL0181N, "The string
representation of a datetime value is out of range."

I have tried using the DateTime.TimeOfDay property, the
DateTime.TimeOfDay.Ticks property, the DateTime object, and as many different
string representations as I could come up with and each time I get the same
error.

Any ideas would be appreciated.

Thanks
--
Dale Preston
MCAD C#
MCSE, MCDBA

推荐答案



Dale写道:

Dale wrote:
我试图在DB2时间字段usinc C#和IBM管理的DB2数据提供程序中存储时间。我得到的错误是SQL0181N,字符串
表示日期时间值超出范围。

我已经尝试使用DateTime.TimeOfDay属性,
DateTime.TimeOfDay.Ticks属性,DateTime对象,以及我可以想出的多个不同的字符串表示,每次我都得到相同的
错误。

任何我们将不胜感激。
I am trying to store a time in a DB2 time field usinc C# and the IBM managed
DB2 data provider. The error I am getting is SQL0181N, "The string
representation of a datetime value is out of range."

I have tried using the DateTime.TimeOfDay property, the
DateTime.TimeOfDay.Ticks property, the DateTime object, and as many different
string representations as I could come up with and each time I get the same
error.

Any ideas would be appreciated.



这是在VB中,但我认为你会发现它很容易理解:

http://www.starquest.com/Supportdocs...e_formats.html


Matt


This is in VB, but I think you will find it easy enough to understand:

http://www.starquest.com/Supportdocs...e_formats.html

Matt


Dale写道:
Dale wrote:
我试图存储一个DB2时间字段中的时间usinc C#和IBM管理的DB2数据提供程序。我得到的错误是SQL0181N,
字符串表示的日期时间值超出范围。

我尝试使用DateTime.TimeOfDay属性,
DateTime.TimeOfDay.Ticks属性,DateTime对象,以及尽可能多的不同字符串表示,因为我可以想出每个
时间我得到相同的错误。
I am trying to store a time in a DB2 time field usinc C# and the IBM
managed DB2 data provider. The error I am getting is SQL0181N, "The
string representation of a datetime value is out of range."

I have tried using the DateTime.TimeOfDay property, the
DateTime.TimeOfDay.Ticks property, the DateTime object, and as many
different string representations as I could come up with and each
time I get the same error.




你的代码是什么?你能粘贴一些你试过的代码吗?无论哪种方式,

首先转换为Timespan或DateTime

对象(通常,提供者工作所需的一切)通常更好。

然后将该对象作为值传递而不是使用字符串。


FB


-

---------------------------------------------- --------------------------

获取LLBLGen Pro,.NET的高效O / R映射: http://www.llblgen.com

我的.NET博客:< a rel =nofollowhref =http://weblogs.asp.net/fboumatarget =_ blank> http://weblogs.asp.net/fbouma

Microsoft MVP(C#)

------------------------------------- -----------------------------------



What is your code? Could you paste some code you tried? Either way,
it''s often a better idea to first convert to a Timespan or DateTime
object (in general, whatever is necessary for the provider to work) and
then pass that object as value instead of using strings.

FB

--
------------------------------------------------------------------------
Get LLBLGen Pro, productive O/R mapping for .NET: http://www.llblgen.com
My .NET blog: http://weblogs.asp.net/fbouma
Microsoft MVP (C#)
------------------------------------------------------------------------


Matt,


当我看到这篇文章时,我很兴奋,因为它显示了我没有尝试的方式

。但是当我尝试传递格式化的时间值时,我得到了相同的

结果。当我通过CURRENT_TIME时,这很有效。问题是我将
存储在两个不同的表中用于审计目的,并且他们必须完全匹配
所以我使用DateTime.Now创建一个DateTime然后我需要这两个表都存储了这个时间。


这里是根据你发给我的页面格式化的SQL:


UPDATE HR.EMPLOYEES SET C_LAST_UPDTE_UID =''PRESTD'',D_LAST_UPDTE =

''01 / 26/2006'',O_LAST_UPDTE_TIME =''07 .48.26.0000''在哪里C_EMPLE_NO =

''89798798'';


D_LAST_UPDTE是一个日期字段,该部分有效。 O_LAST_UPDTE_TIME是一个

时间字段,它是导致错误的字段。我已经为O_LAST_UPDTE_TIME尝试了以下格式的所有




//首先我生成了一个DateTime值:

DateTime updateTime = DateTime.Now;


//然后使用以下每个值替换''07 .48.26.0000'',无论是否有单一的

引用:


updateTime.TimeOfDay

updateTime.TimeOfDay.Ticks

updateTime.Ticks

updateTime的ToString(QUOT; HH:MM:SS")

updateTime.TimeOfDay.ToString()

updateTime.TimeOfDay.Ticks.ToString()


所有这些都会导致同样的错误。

-

Dale Preston

MCAD C#

MCSE,MCDBA

" Matt"写道:
Matt,

When I saw this article, I was excited because it showed ways I hadn''t tried
yet. But when I tried passing the formatted time value, I got the same
result. When I passed CURRENT_TIME, that worked. The problem is that I
store the time in two different tables for auditing purposes and they have to
match exactly so I create a DateTime using DateTime.Now and then I need to
store that time in both tables.

Here''s the SQL formatted based on the page you sent me to:

UPDATE HR.EMPLOYEES SET C_LAST_UPDTE_UID = ''PRESTD'',D_LAST_UPDTE =
''01/26/2006'',O_LAST_UPDTE_TIME = ''07.48.26.0000'' WHERE C_EMPLE_NO =
''89798798'';

D_LAST_UPDTE is a date field and that portion works. O_LAST_UPDTE_TIME is a
time field and it is the one causing the error. I have tried all of the
following formats for O_LAST_UPDTE_TIME:

// first I generated a DateTime value:
DateTime updateTime = DateTime.Now;

// then replaced the ''07.48.26.0000'' with each of the following values, both
with and without the single quotes:

updateTime.TimeOfDay
updateTime.TimeOfDay.Ticks
updateTime.Ticks
updateTime.ToString("HH:mm:ss")
updateTime.TimeOfDay.ToString()
updateTime.TimeOfDay.Ticks.ToString()

All of them result in the same error.
--
Dale Preston
MCAD C#
MCSE, MCDBA
"Matt" wrote:

Dale写道:

Dale wrote:
我试图将时间存储在DB2时间字段usinc C#和IBM管理的
DB2数据提供程序。我得到的错误是SQL0181N,字符串
表示日期时间值超出范围。

我已经尝试使用DateTime.TimeOfDay属性,
DateTime.TimeOfDay.Ticks属性,DateTime对象,以及我可以想出的多个不同的字符串表示,每次我都得到相同的
错误。

任何我们将不胜感激。
I am trying to store a time in a DB2 time field usinc C# and the IBM managed
DB2 data provider. The error I am getting is SQL0181N, "The string
representation of a datetime value is out of range."

I have tried using the DateTime.TimeOfDay property, the
DateTime.TimeOfDay.Ticks property, the DateTime object, and as many different
string representations as I could come up with and each time I get the same
error.

Any ideas would be appreciated.



这是在VB中,但我认为你会发现它很容易理解:

http://www.starquest.com/Supportdocs...e_formats.html

Matt


This is in VB, but I think you will find it easy enough to understand:

http://www.starquest.com/Supportdocs...e_formats.html

Matt



这篇关于带有.Net的DB2时间字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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