Geeks With Blogs
Create Fun Things - Samer's Developer Blog Development Blog for C#, .NET and Obj-C

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!

Posted on Wednesday, July 22, 2009 6:04 PM | Back to top


Comments on this post: Fixing “Row not found or changed” LINQ error

# re: Fixing “Row not found or changed” LINQ error
Requesting Gravatar...
You are a genius.
Left by anonymous on Apr 05, 2010 10:55 PM

# re: Fixing “Row not found or changed” LINQ error
Requesting Gravatar...
Tried it in a GridView. didn't solve this error but now the update uses my hidden ID field. thanks!
Left by Roy on May 12, 2010 10:40 AM

# re: Fixing “Row not found or changed” LINQ error
Requesting Gravatar...
Thank u. :)
Left by thazin on Jun 10, 2010 9:57 PM

Your comment:
 (will show your gravatar)


Copyright © samerpaul | Powered by: GeeksWithBlogs.net