1

What will be the equivalent data type for Timestamp in C#? If I want to retrieve data from SQL server and want to map with C# object?

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
bulbul bd
  • 166
  • 1
  • 1
  • 9
  • Just to be clear you know that Timestamp is not an actual time stamp and holds no date time information ? its used for row versioning, and can be converted to `byte[8]` – TheGeneral Feb 25 '19 at 06:50
  • "Timestamp" is very confusing, as documented [here](https://stackoverflow.com/questions/6334777/what-does-a-timestamp-in-t-sql-mean-in-c) on Stack Overflow – MindSwipe Feb 25 '19 at 06:50
  • @MichaelRandall, I know Timestamp is using for row versioning but what if we want to map with C# model ? – bulbul bd Feb 25 '19 at 06:53
  • "DateTime" will get you you the date with time "MM/dd/yyyy hh:mm tt" – Vishal Feb 25 '19 at 06:57

2 Answers2

0

SQL Server Timestamp data type is very confusing. It's more like a version number and holds no date/ time information and as of SQL Server 2008 was renamed to "rowversion". That being said if you really need to map "timestamp" column the best match is probably just a plain old long (or ulong depending on how SQL Server treats big/ little endianess)

If you want a DateTime equivalent you'll want to use the datetime type in SQL Server instead, which maps directly and easily to DateTime in C#.

MindSwipe
  • 7,193
  • 24
  • 47
  • This answer looks like a carbon copy of https://stackoverflow.com/a/6334815/11683 with some bits slightly rearranged. – GSerg Feb 25 '19 at 07:03
-1

When mapping the c# object, you might want to declare a property with either byte[] or long.

Hope this helps.

Labib Hussain
  • 590
  • 5
  • 9