i want to do above.
i have an object of table in c#.
i want to do above.
i have an object of table in c#.
A SQL TimeStamp is based on insert / update order on your sql server. There is no way to assign it from within C#. I doubt SQL will even allow you to update a column of type TimeStamp.
TimeStamp is a binary sequence. (8 bytes I believe.) There is no correlation to a DateTime. Nothing to display for the user on a page.
If you want to show the user when a record was last modified or first created, you will have to maintain separate fields of type DateTime and update the values in either your application or within sql using sprocs or triggers.
According to the documentation, the Transact-SQL timestamp data type is just an incrementing number and does not preserve a date or a time. You can't convert that to a meaningful DateTime
value.
The documentation says that it's an 8-byte value. So, if it's stored in a System.Data.Linq.Binary
, you could convert it to a long
with this code:
System.Data.Linq.Binary timestampValue;
// Somehow get a reference to the SQL timestamp you're interested in
// Use BitConverter to convert the 8 bytes to a long
long timestampLong = BitConverter.ToInt64(timestampValue.ToArray(), 0);
You could try to convert that value to a DateTime
by calling the constructor that takes a ticks
value, but the results would be meaningless. You might also encounter an exception if the ticks
value is out of range.