0

I created a new column in an existing database, to allow me a RowVersion for concurrency operations:

alter table MyTable add ColumnName rowversion

In my class I added the following property

public byte[] ColumnName { get; set; }

In the one method that uses this class i get the error when using this property

Cannot implicitly convert type 'System.Data.Linq.Binary' to 'byte[]'

I overcome this by adding ToArray (myObj.ColumnName.ToArray()) to the property.

In my ASP .Net page I add a hidden control to a Repeater and assign the value as

RowHiddenField.Value = Convert.ToBase64String(myObj.ColumnName);

Now i am trying to compare this column with the object passed in

public bool RowModified(MyObject myObj)

objFound = GetAllObjects.First(o=> o.ID = myObj.ID);

If (objFound.ColumnName == myObj.ColumnName)

but the values are never the same?

After reading a few links in converting TimeStamp, i've attempted them but either they didnt work (could be i was confused and did something wrong) or it didnt apply to my scenario.

Appreciate any help on this.

Patrick
  • 1,717
  • 7
  • 21
  • 28
Computer
  • 2,149
  • 7
  • 34
  • 71
  • http://stackoverflow.com/questions/4470807/sql-server-rowversion-timestamp-comparisons http://stackoverflow.com/questions/7713143/how-compare-cast-sql-rowversion-field-data-in-c-sharp – mss Oct 17 '14 at 10:06
  • You seem to have a number of problems. What's your actual question? – Gert Arnold Oct 17 '14 at 10:18
  • Im trying to compare the value passed from my hidden field to compare against the current row version value to see if the data has been altered since the page was loaded. @mss i did read that link but there seems to be significant changes required form my end in order to achieve the same. Im not sure if theres an easier way as im not sure how i would get the byte values when i have converted them to string? – Computer Oct 17 '14 at 10:49

1 Answers1

0

I don't know anything about the SQL rowversion format. Seems like the links offered by mss in the comments will help you if you care about that.

But if all you care about is equality, then it should be sufficient to just compare the two byte[] objects. The problem with your code is that arrays don't override Equals() or provide an == overload. So using == just compares the two object references, which are always the same.

See this previously-asked question for details of how to correctly (and easily) compare two arrays: Easiest way to compare arrays in C#

Community
  • 1
  • 1
Peter Duniho
  • 68,759
  • 7
  • 102
  • 136