This topic has been archived. It cannot be replied.
-
工作学习 / IT技术讨论 / 请教timestamp类型。谢谢。我从一个storeprocedure中取出一个timestamp 类型变量(output),作为另一个storeprocedure的input.
1storeprocedure1
dim timestamp as string
params(0) = New SqlParameter("@tmstp", SqlDbType.Timestamp, 8)
params(0).Direction = ParameterDirection.Output
timestamp=params(0).value.tostring
2 storeprocedure2
params(0) = New SqlParameter("@tmstp", SqlDbType.Timestamp, 8)
params(0).Direction = ParameterDirection.Input
params(0).Value = timeStamp
storeproedure2 该参数出错。请问,我应该怎么办。
-lilyba(sunshine困惑不懂装懂);
2003-12-4
{508}
(#1498102@0)
-
In 2, params(0).Value should also be timestamp datatype, I am not familiar with VB, in C#, params(0).Value = Convert.ToDateTime(timestamp);
-cloud2001(卷云溶月*fallen*);
2003-12-4
(#1498173@0)
-
谢谢,不过,这个timestamp应该是个binary,好像不能用时间类型。
-lilyba(sunshine困惑不懂装懂);
2003-12-4
(#1498234@0)
-
up
-lilyba(sunshine困惑不懂装懂);
2003-12-4
(#1498304@0)
-
give it a try: params(0).Value = Convert.FromBase64String(timeStamp);
-hillxie(我叫不紧张);
2003-12-4
(#1498363@0)
-
我试过了,告诉我data format不对。这是我的错误信息:Message "Input string was not in a correct format."
-lilyba(sunshine困惑不懂装懂);
2003-12-4
(#1498375@0)
-
Don't insert anything into this column, I think timestamp data type will automatically filled by system using current system time.
-wnms2000(乘风归去);
2003-12-4
(#1498385@0)
-
Sorry,没讲明白,第二个timestamp作为input,实际上不是用来insert,而是作为参数,比较的。
-lilyba(sunshine困惑不懂装懂);
2003-12-4
(#1498409@0)
-
params(0).Value = timeStamp--->timestamp 是一个string,而Parameter要一个TimeStamp. 你把它传进去当然不对。而且你似乎也用错数据类型了,不应该用这种类型的变量
-miketany(MIKE老狼);
2003-12-4
(#1498393@0)
-
怎么办呢?
-lilyba(sunshine困惑不懂装懂);
2003-12-4
(#1498410@0)
-
你一定要用你可以把存储过程的那个参数改为Varchar, 传进去后Cast成TimeStamp
-miketany(MIKE老狼);
2003-12-4
(#1498424@0)
-
不是特别明白。你能帮我把source code 改一下么?谢谢你了。
-lilyba(sunshine困惑不懂装懂);
2003-12-4
(#1498443@0)
-
其实你把timeStamp直接声明成System.Data.SqlClient.SqlDbType.TimeStamp不就好了吗?timestamp=params(0).value 就不会有变量类型的问题了
-miketany(MIKE老狼);
2003-12-4
(#1498533@0)
-
yes, but SqlDbType.TimeStamp is not a class...
-hillxie(我叫不紧张);
2003-12-4
(#1498551@0)
-
不知道下面的方法是否可以解决。今天晚上做做实验吧。谢谢你们了,dx们。
-lilyba(sunshine困惑不懂装懂);
2003-12-4
{565}
(#1498581@0)
-
也不用这么麻烦吧,你能改存储过程你直接把变量改成int, varchar不就可以了么。SqlDbType.TimeStamp类型是byte[8], 声明一个byte数组不好一些吗?
-miketany(MIKE老狼);
2003-12-4
(#1498632@0)
-
我其实是这样做的,而且经过两次转换之后,结果一模一样,都是长度为8,类型为byte的arraylist。但是运行storeprocedure总是出现data format 不对的错误。取数,for output param: timeStamp = Convert.ToBase64String(CType(params(5).Value, Byte()))
input param:
params(4).Value = Convert.FromBase64String(timeStamp.ToString())
-lilyba(sunshine困惑不懂装懂);
2003-12-4
{201}
(#1498640@0)
-
Have you tried this:1storeprocedure1
dim timestamp
params(0) = New SqlParameter("@tmstp", SqlDbType.Timestamp, 8)
params(0).Direction = ParameterDirection.Output
timestamp=params(0).value
don't do any convertion in the first code snippet.
-wnms2000(乘风归去);
2003-12-4
{228}
(#1498665@0)
-
I tried, not work. :('''''
-lilyba(sunshine困惑不懂装懂);
2003-12-4
(#1498688@0)
-
Agree, the Byte[] should work.
-hillxie(我叫不紧张);
2003-12-4
(#1498663@0)
-
Try this:I express using c#, you can try it in the same way using VB.Net:
1. storeprocedure1
Byte[] timeStamp;
params[0] = New SqlParameter("@tmstp", SqlDbType.Timestamp, 8);
params[0].Direction = ParameterDirection.Output;
timestamp = (Byte[])params[0].value;
2. storeprocedure2:
params[0] = New SqlParameter("@tmstp", SqlDbType.Timestamp, 8);
params[0].Direction = ParameterDirection.Input;
params[0].Value = timeStamp;
-hillxie(我叫不紧张);
2003-12-4
{435}
(#1498653@0)
-
Thanks, i will try this tonight.
-lilyba(sunshine困惑不懂装懂);
2003-12-4
(#1498689@0)
-
msdn
-guestagain(guest again);
2003-12-4
(#1498713@0)
-
Thanks, it works. This should be the easiest way.
-lilyba(sunshine困惑不懂装懂);
2003-12-8
(#1504373@0)