×

Loading...
Ad by
  • 最优利率和cashback可以申请特批,好信用好收入offer更好。请点链接扫码加微信咨询,Scotiabank -- Nick Zhang 6478812600。
Ad by
  • 最优利率和cashback可以申请特批,好信用好收入offer更好。请点链接扫码加微信咨询,Scotiabank -- Nick Zhang 6478812600。

不知道下面的方法是否可以解决。今天晚上做做实验吧。谢谢你们了,dx们。

Function dbTimeStamp (SqlTimeStamp As Variant) As String

' This function creates a hex digit timestamp 'string' which
' can be passed to any update store procedure

Dim cString As String
Dim x As Integer

cString = "0x"

For x = 1 To Len(SqlTimeStamp)

cString = cString + Right$("00" + Hex$(Asc(Mid$(SqlTimeStamp, x,
1))), 2)

Next

dbTimeStamp = cString

End Function




UPDATE tablename SET col = col FROM table
WHERE key = key AND timestamp = dbTimeStamp(VB timestamp variable)
Report

Replies, comments and Discussions:

  • 工作学习 / 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 该参数出错。请问,我应该怎么办。
    • In 2, params(0).Value should also be timestamp datatype, I am not familiar with VB, in C#, params(0).Value = Convert.ToDateTime(timestamp);
      • 谢谢,不过,这个timestamp应该是个binary,好像不能用时间类型。
        • up
    • give it a try: params(0).Value = Convert.FromBase64String(timeStamp);
      • 我试过了,告诉我data format不对。这是我的错误信息:Message "Input string was not in a correct format."
        • Don't insert anything into this column, I think timestamp data type will automatically filled by system using current system time.
          • Sorry,没讲明白,第二个timestamp作为input,实际上不是用来insert,而是作为参数,比较的。
    • params(0).Value = timeStamp--->timestamp 是一个string,而Parameter要一个TimeStamp. 你把它传进去当然不对。而且你似乎也用错数据类型了,不应该用这种类型的变量
      • 怎么办呢?
        • 你一定要用你可以把存储过程的那个参数改为Varchar, 传进去后Cast成TimeStamp
          • 不是特别明白。你能帮我把source code 改一下么?谢谢你了。
            • 其实你把timeStamp直接声明成System.Data.SqlClient.SqlDbType.TimeStamp不就好了吗?timestamp=params(0).value 就不会有变量类型的问题了
              • yes, but SqlDbType.TimeStamp is not a class...
    • 不知道下面的方法是否可以解决。今天晚上做做实验吧。谢谢你们了,dx们。
      Function dbTimeStamp (SqlTimeStamp As Variant) As String

      ' This function creates a hex digit timestamp 'string' which
      ' can be passed to any update store procedure

      Dim cString As String
      Dim x As Integer

      cString = "0x"

      For x = 1 To Len(SqlTimeStamp)

      cString = cString + Right$("00" + Hex$(Asc(Mid$(SqlTimeStamp, x,
      1))), 2)

      Next

      dbTimeStamp = cString

      End Function




      UPDATE tablename SET col = col FROM table
      WHERE key = key AND timestamp = dbTimeStamp(VB timestamp variable)
      • 也不用这么麻烦吧,你能改存储过程你直接把变量改成int, varchar不就可以了么。SqlDbType.TimeStamp类型是byte[8], 声明一个byte数组不好一些吗?
        • 我其实是这样做的,而且经过两次转换之后,结果一模一样,都是长度为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())
          • 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.
            • I tried, not work. :('''''
        • Agree, the Byte[] should work.
    • 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;
      • Thanks, i will try this tonight.
    • msdn
      • Thanks, it works. This should be the easiest way.