Some misc. code to work with a SQL timestamp (aka rowversion):
I sometimes like making it an attribute on my page:
Here I store the original value and the rowversion...
<asp:foobar runat=server RowVersion='<%#
ByteToString(Container.DataItem("RowVersion")) %>' OriginalValue='<%#
Container.DataItem("ApprovedHours") %>' />
Protected Function ByteToString(ByVal rowVersion As Byte()) As String
Return Convert.ToBase64String(rowVersion)
End Function
Dim ApproveHours As Int16 =
CType(CType(grid.Items(selectedIndex).FindControl( "lblApproveHours"),
Label).Attributes("OriginalValue"), Int16)
Dim sRowVersion As String =
CType(CType(grid.Items(selectedIndex).FindControl( "lblApproveHours"),
Label).Attributes("RowVersion"), String)
Dim byteRowVersion() As Byte = Convert.FromBase64String(sRowVersion)
Here is how to use with a parameter...
Dim rowVersion() As Byte
With cmd.Parameters.Add("@RowVersion", SqlDbType.Timestamp)
.Value = rowVersion
.Direction = ParameterDirection.InputOutput
End With
rowVersion = CType(cmd.Parameters("@RowVersion").Value, Byte())
HTH,
Greg
"mybappy" <my*****@discussions.microsoft.com> wrote in message
news:AD**********************************@microsof t.com...
Hi:
I am trying to use timestamp field of SQL Server to maintain concurrency.
My
problem is how do I store the timestamp value in my webform. The hidden
field
does not work as I get some cast error. If I can not store the value, how
should I return the timestamp to the database (with other values) to
compare
with the current timestamp to check for updates.
You answers will be greatly appreciated.
Thanks