How Do I Read A Rowversion or Timestamp SQL Server Data Type From a SQLDataReader to a C# Variable

后端 未结 2 1960
一生所求
一生所求 2021-01-19 01:37

I have a SQL Server 2012 database. Each table has a set of audit fields. One is a column named RowVer with a datatype of timestamp (same as rowversion

2条回答
  •  猫巷女王i
    2021-01-19 01:55

    If you are using .NET 4.5 or newer you can do

    user.RowVersion = rdr.GetFieldValue(18);
    

    If you are on 4.0 or older you will need to perform a cast.

    user.RowVersion = rdr.GetValue(18) as byte[];
    

提交回复
热议问题