title: How to pass a timestamp value parameter from C# to SQL
body: <p>I have a stored procedure where the rowversion is of type Timestamp </p>
  
  <pre><code>CREATE PROCEDURE GetCoverages
      @PageStart INT = 0,
      @PageSize INT = 50000,
      @RowVersion TIMESTAMP = NULL
  AS
      SELECT
          * 
      FROM
          Coverages cov
      WHERE
          @RowVersion IS NULL OR cov.RowVersion &gt; @RowVersion
      ORDER BY 
          RowVersion 
          OFFSET @PageStart ROWS
          FETCH NEXT @PageSize ROWS ONLY   
  GO
  </code></pre>
  
  <p>On the C# side, I have this following code:</p>
  
  <pre><code>            var rowVersionParam = new SqlParameter()
              {
                  ParameterName = "@RowVersion",
                  SqlDbType = SqlDbType.Timestamp,
                  Direction = ParameterDirection.Input,
                  Value = rowVersion != null ? BitConverter.GetBytes(Convert.ToInt64(rowVersion)) : (object)DBNull.Value
              };
  
              var prms = new SqlParameter[]
              {
                  new SqlParameter("@PageStart", index),
                  new SqlParameter("@PageSize", pageSize),
                  rowVersionParam
              };
  
              var coverages = await outerRingDb.Set&lt;SpCoverages&gt;()
                                                  .FromSqlRaw("EXEC GetCoverages @PageStart, @PageSize, @RowVersion", prms)
                                                  .ToListAsync(cancellationToken);
  </code></pre>
  
  <p>In my C# code, the rowVersion is of type <code>ulong?</code> (nullable) and when I am including it in my parameter collection, I am converting it to byte array (<code>byte[]</code>) using the <code>BitConverter</code>. In the debug mode, I see that the <code>rowVersion</code> parameter is set to 50353967.</p>
  
  <p>The problem that I am having is that, when I get the latest rowversion (ie. 0x000000000300572F) from a table (this table is used as a record keeper to store the latest rowversion when it was last synced) and when i run the debug run the code, C# executes the stored procedure and tells me that there are no records. </p>
  
  <p>When I execute the stored procedure directly like this: </p>
  
  <pre><code>  EXEC GetCoverages 0, 50000, 0x000000000300572F`
  </code></pre>
  
  <p>SQL Server returns results. </p>
  
  <p>I am not sure what I am doing wrong here or how the C# is passing my timestamp value to SQL Server. Any insight to this issue would be helpful. Thanks in advance.</p>