1

How to store a TSQL timestamp/rowversion value in a HTML Hidden input-field as a "comparable" value?

E.g.:
I get a "timestamp" from a database table-row as a byte-array. Now I want to store this value as a string in my HTML document. After a submit I want to read out the timestamp the user got as he requested the page and compare it with the database current timestamp.

Werner
  • 2,126
  • 2
  • 22
  • 34

2 Answers2

2
byte[] data = dataReader["dt"] as byte[];

You'll have to store it in the hidden field as a string:

hiddenField.Value = Convert.ToBase64String(data);

And then convert it back:

byte[] data = Convert.FromBase64String(hiddenField.Value);

Comparison:

bool areEqual = data .SequenceEqual(data )

PS: TimeStamp in SqlServer doesn't mean DateTime! This is actually a byte array with length of 8. What does a timestamp in T-Sql mean in C#?

Community
  • 1
  • 1
Artur Udod
  • 4,465
  • 1
  • 29
  • 58
0

Added a property on your model which generated a html-friendly version of the bytearray timestamp, for example { 0, 120, 200, 20, 52, 33 } turns into "0 120 200 20 52 33". Make it so this property can also be set which in turns updates the timestamp byte array.

Bind this property to a hidden field in the rendered page.

When the form if posted, the setting of the extra property sets the value of the timestamp byte array. Now you can compare it to the db timestamp.

Maarten
  • 22,527
  • 3
  • 47
  • 68