Fixing “Row not found or changed” LINQ error

So over the past few months I have hit so many bugs and errors coding in .NET, that I thought I’d share a some of them that I spent several hours trying to fix, only to realize it was a simple solution. This will be a multi-part series, if all goes to plan.

LINQ Error: “Row not found or changed”. This one took some head scratching. It’s a pretty generic error, and unfortunately the internet wasn’t of great use to finding the answer.

I use timestamp columns in almost every table, since it makes updating values through LINQ a lot easier. (You can use the Attach() method with a timestamp column.)

What was happening is that when I was updating the values in my ListView (i.e. it was in edit mode, and I clicked Update), the timestamp column (named “Version” in my program) was not being sent in the array of values. The quick fix? Add “Version” to the DataKeyNames[] collection specified in the ListView declaration and it works like a charm.

     <asp:ListView ID="myListView" runat="server" DataSourceID="myDataSource"
    InsertItemPosition="LastItem" DataKeyNames="Version, DateCreated, CreatedBy">

So now the Attach method was being fed the needed column, as well as a few other house keeping columns I use in my database, and it was updating without any problem!

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati
Print | posted on Wednesday, July 22, 2009 6:04 PM

Feedback

# re: Fixing “Row not found or changed” LINQ error

left by anonymous at 4/5/2010 10:55 PM Gravatar
You are a genius.

# re: Fixing “Row not found or changed” LINQ error

left by Roy at 5/12/2010 10:40 AM Gravatar
Tried it in a GridView. didn't solve this error but now the update uses my hidden ID field. thanks!

# re: Fixing “Row not found or changed” LINQ error

left by thazin at 6/10/2010 9:57 PM Gravatar
Thank u. :)
Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification: