Re: Timestamp Value - please help

From: Richard (anonymous_at_discussions.microsoft.com)
Date: 05/04/04


Date: Mon, 3 May 2004 21:01:05 -0700

Thank you. The following topic in MSDN gives an example of converting hex to string. I tweaked the function given in the following link slightly and so far it has worked. I'm including it if it helps anyone else:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemByteClassTopic.asp.

>From what I've read, Timestamp is an array of byte, so returning it from a datatable would look like this:

Private mintEmpID As Integer
Private mstrFN As String
Private mstrLN As String
Private mbytTS(8) As Byte

'Here's my data.
With ds.Tables(0).Rows(0)
  mintEmpID = .Item("EmpID")
  mstrFN = .Item("FirstName")
  mstrLN = .Item("LastName")
  mbytTS = .Item("TS")
End With

Now, to format the timestamp for use in a Where clause:

Private sql as String
Private str as String
'Pass the timestamp to conversion function.
sql = "Update Employees Set FirstName='" & mstrFN & "', LastName='" & mstrLN & "' Where EmpID = " & mintEmpID & " And TS =" & ToHexString(mbytTS)

Public Shared Function ToHexString(ByVal bytes() As Byte) As String
'Documentation states timestamp must begin with 0x.
Dim hexStr As String = "0x"
Dim i As Integer

For i = 0 To bytes.Length - 1
  'If it's a single digit, append a zero in front of it.
  If Hex(bytes(i)).Length = 1 Then
     hexStr &= 0 & Hex(bytes(i))
  Else
     hexStr = hexStr + Hex(bytes(i))
  End If
Next i

Return hexStr

End Function

Once the record is updated, I retrieve the updated TS for future updates.

     ----- DalePres wrote: -----
     
     BOL indicates that the Timestamp column is syntactically identical to a
     binary(8). A nullable timestamp is equal to a varbinary. The topic "Cast
     and Convert" in BOL describes the implicit conversions possible for a
     timestamp.
     
     Dale
     
     
     "Richard" <anonymous@discussions.microsoft.com> wrote in message
     news:A0C9C97A-1C12-407D-BD3C-91C6626C8DE5@microsoft.com...
> Thank you for your reply. My apologies for being confusing. The column is
     in SQL Server 2000, and its datatype is Timestamp. I'm aware it is not an
     actual time, but in every .Net/SS book I've read, they recommended the
     timestamp for multiuser environments, because it updates automatically when
     a row is updated and is guaranteed (?) to be unique. By comparing the value
     in a datatable against the one in the database, I would be assured that if
     they don't match, the database was already changed (and I can take steps to
     inform the user). Unfortunately, none of the books go so far as to show how
     to go from datacentric to object-oriented, thus my question.
>> ----- DalePres wrote: -----
>> A timestamp value isn't really designed to be retrieved or queried
     against.
> It is not even guaranteed to remain the same over time since each
     time you
> change or update a row, the timestamp changes. Rows updated later
     will
> always have a higher timestamp value than rows updated earlier.
     That's the
> only assumption you should make. Timestamps are intended to allow
     you to
> sort based on update time but do not represent actual times.
>> If you want to record row update/creation times for later retrieval,
     use a
> datetime column with GETDATE() so that all the times are in server
     time.
> Though not guaranteed to give as reliable of a timestamp as a
     timestamp
> column would, in all but the most rare of situations, it would be
     completely
> reliable and/or acceptable.
>> Dale
>



Relevant Pages

  • Timestamp Value - please help
    ... Private mintEmpID As Integer ... Private mstrFN As String ... When the user changes the data and saves, the update query using the TS in the Where clause fails because mbytTS reads 'System.Byte' instead of the actual timestamp. ...
    (microsoft.public.dotnet.framework.adonet)
  • Timestamp
    ... How do you get the actual value of a timestamp from a SQL Server 2000 database table using VB.Net? ... Private mintEmpID As Integer ... Private mstrFN As String ...
    (microsoft.public.dotnet.languages.vb)
  • Re: [PhP - dB] About Formatting a Date Result
    ... In the MySQL database the field is set to date not timestamp as you ... foresight has stored a string date instead of a timestamp, ... and can format your date to that used, in the config files, for any user ...
    (php.general)
  • Re: yamp yet another multiline post
    ... start app timestamp ... return string from application ... app complete timestamp ... Mike Dundas ...
    (comp.lang.awk)
  • Re: yamp yet another multiline post
    ... start app timestamp ... return string from application ... app complete timestamp ... moving solaris awk to awk.old and linking xpg4 awk instead? ...
    (comp.lang.awk)