locked
Rowversion/Timestamp for checking change in row RRS feed

  • Question

  • I use VS 2012 and SQl Server 2012.

    I first tried to use Timestamp and apparently it has been replaced by Rowversion. In SQL Server 2012 I cannot find a Rowversion datatype, but there is a Timestamp datatype.

    Can someone suggest which datatype should be used (I guess Timestamp, since Rowversion is not there).

    I want to use Rowversion/Timestamp to check whether a specific row has changed, after the row has been modified by the user. I use VB.net and would appreciate it if Someone could provide a real example.

    Thanks, John

    Wednesday, March 19, 2014 7:26 AM

Answers

  • Yes, you can read timestamp column value using a datareader. You have to convert it into byte array before comparing, like

    code

    Dim tspTS As Byte() = drd("tspTimestamp")
    Dim dgvTS As Byte() = DataGridView1.Rows(rowIndex).Cells(timeStampColumnIndex).Value
    If tspTS.SequenceEqual(dgvTS) Then
        MessageBox.Show("Equal")
    Else
        MessageBox.Show("Unequal")
    End If


    Thursday, March 20, 2014 12:36 PM
  • Very good Jeetendra,

    Timestamp is the way to go.

    Thanks,

    John

    • Marked as answer by JohnPapa05 Thursday, March 20, 2014 1:44 PM
    Thursday, March 20, 2014 1:44 PM

All replies

  • You must use rowversion, as timestamp is deprecated and will be discontinued in future versions of the sql server database technology.

    Wednesday, March 19, 2014 10:40 AM
  • You have opened two similar threads, I suggest you to remove the other one.

    Wednesday, March 19, 2014 10:42 AM
  • Thanks for the reply. The confusing part is that the datatype is still Timestamp, right?

    Regarding the second (similar) thread, which I have deleted, it was submitted by mistake. The second sentence in the thread was not completed ...

    Wednesday, March 19, 2014 11:15 AM
  • They are pretty much same. Till Sql Server 2005, it was timestamp and rowversion was synonym, whereas from Sql Server 2008, it was rowversion and timestamp is synonym. As per MSDN, timestamp will be discontinued in future versions and so it recommends to use rowversion.


    Wednesday, March 19, 2014 12:53 PM
  • I might end up using a simple datetime field, so as to avoid future changes in the software.

    Thanks for your help anyway,

    John

    Wednesday, March 19, 2014 1:15 PM
  • I didn't mean that. I said timestamp will be discontinued not rowversion.

    And datetime column will not help you in row versioning.

    You must avoid using timestamp, instead use rowversion.

    Wednesday, March 19, 2014 1:32 PM
  • I meant generally if there is another change.

    Why wouldn't a datetime field help in row versioning? I only require an indication that the row has been changed by someone.

    John

    Wednesday, March 19, 2014 1:36 PM
  • The difference between rowversion and other data types is, rowversion column value is auto updated whenever any value of column in a row is updated without any external help or intervention. Whereas if you plan to use datetime then you have to take care of updating the value of this column.

    And Microsoft cannot scrap rowversion/timestamp concept, here they are just changing the name not meaning and purpose.

    So, you can confidently go ahead with rowversion.

    I believe that Microsoft will not change the rowversion name in future.

    Wednesday, March 19, 2014 1:43 PM
  • Thanks. Definitely a big advantage.

    Do you have any vb.net code which shows the comparison between two Rowversions?

    John

    Wednesday, March 19, 2014 1:50 PM
  • Code

    Dim rowver1 As Byte() = {1, 1, 1, 1, 1, 1, 1, 1}
    Dim rowver2 As Byte() = {1, 1, 1, 1, 1, 1, 1, 1}
    If rowver1.SequenceEqual(rowver2) Then
        MessageBox.Show("Equal")
    Else
        MessageBox.Show("Unequal")
    End If

    Wednesday, March 19, 2014 1:59 PM
  • Thanks.

    To retrieve the remote Rowversion value (the value on SQL Server) do I access it like any other 8-byte variable or is there a simple way?

    Wednesday, March 19, 2014 2:19 PM
  • Rowversion is represented as an array of byte (size of 8) in vb.net

    Wednesday, March 19, 2014 2:21 PM
  • Please mark response as answer if they help.

    • Marked as answer by JohnPapa05 Thursday, March 20, 2014 7:45 AM
    • Unmarked as answer by JohnPapa05 Thursday, March 20, 2014 11:36 AM
    Wednesday, March 19, 2014 3:10 PM
  • Just coming back for a second.

    I have Timestamp field, "tsp" in a table in SQL Server. Can I use a SqlDataReader to read this value, like

                If funOpenConnection(cnn) = False Then

                    Exit Sub

                End If

                Dim strCommand As String

                strCommand = "SELECT intDoctorID, nvcDoctorSurname01, nvcDoctorName01, bitActive, tspTimeStamp " & "FROM tblDoctor"

                Dim cmd As SqlCommand

                cmd = New SqlCommand(strCommand, cnn)

                Dim drd As SqlDataReader

                drd = cmd.ExecuteReader

                If drd.HasRows Then

                    Do While drd.Read

                        If drd("tspTimestamp")……….

    Do I access tspTimestamp with last statement?

    How do I compare with same value on local DGV?

    Thanks again,

    John

    Thursday, March 20, 2014 11:46 AM
  • Yes, you can read timestamp column value using a datareader. You have to convert it into byte array before comparing, like

    code

    Dim tspTS As Byte() = drd("tspTimestamp")
    Dim dgvTS As Byte() = DataGridView1.Rows(rowIndex).Cells(timeStampColumnIndex).Value
    If tspTS.SequenceEqual(dgvTS) Then
        MessageBox.Show("Equal")
    Else
        MessageBox.Show("Unequal")
    End If


    Thursday, March 20, 2014 12:36 PM
  • Very good Jeetendra,

    Timestamp is the way to go.

    Thanks,

    John

    • Marked as answer by JohnPapa05 Thursday, March 20, 2014 1:44 PM
    Thursday, March 20, 2014 1:44 PM