I\'m trying to develop a model object to hold a Sql Server row, and I understand perfectly how to do this except for the T-Sql/SqlServer timestamp. The table is defined as:
The name of the Sql Server timestamp data type is confusing. It's really better to think of it more like a version number — there's no date/time information in there anywhere. In fact, as of Sql Server 2008 the type was renamed to "rowversion".
Most of the time you want the datetime
type in Sql Server instead, which maps easily to DateTime in C#, or perhaps datetime2 if you have a version so Sql Server that supports it. Documentation on the timestamp type is here:
http://msdn.microsoft.com/en-us/library/ms182776(v=sql.90).aspx
If you really must map that timestamp column as-is, the closest match is probably plain old long
(or maybe ulong), but I have no idea how sql server handles byte ordering or big/little endien-ness vs C#.
According to this post
you'll have to cast it to a byte array.
byte[] dt = dataReader["dt"] as byte[];
when retrieving from database
string dt = Convert.ToBase64String(dataReader["dt"] as byte[]);
when passing into database
new SqlParameter("@dt", Convert.FromBase64String(dt))
It's a byte[]
, with a Length
of 8
.