I am trying to delete a selected gridview row using LINQ (No LINQDataSource).
When the selection is changed, the detailsview binding is changed also. I can add a new
I'm having the same problem, and came across this blog, which basically states that Linq-To-Sql has got a problem in it's optimistic concurrency where:
I haven't tried these solutions yet, but will post back here once I have.
I had similar changeconflictexception/"Row not found or changed" when updating a row. Solved it by re-adding the tabbles in the dbml.
For us the problem started when we switched to DateTime2 on the SQL Server side. Just marking fields with Column(DbType = "DateTime2") did not help. So, what happened was that initially on the database side we declared our columns as DateTime2(3) to be "backward compatible" with the old DateTime type and everything seemed to work fine until we noticed that when we use SQL-2-Linq we get the "Row not found or changed" exception in the updates of those date fields. To make the quite-long story short the solution was to do 2 things:
[Column(DbType = "DateTime2(3)", CanBeNull = false)]
public DateTime ModifiedAt {
get => _modifiedAt;
set => _modifiedAt = value.AddTicks(-(value.Ticks % TimeSpan.TicksPerMillisecond));
}
The problem I had was that I had a DateTime type in the .net framework, but our database field was of DateTime2 type, which is higher precision datatype. So when we would submit changes the date fields of the object vs. the DB was just a few nanoseconds off which would cause the concurrency error. This happened when we migrated to a newer MSSQL version and it converted our DateTime fields to DateTime2.
So in our code where we had:
Obj.DateUpdated = DateTime.Now()
We changed it to:
Obj.DateUpdated = DateTime.Parse(DateTime.Now.ToString())
So check your datatypes, especially your date fields, if you get this error after making an upgrade and or migration.
I was able to resolve this issue by executing databind() on the gridview and datasource during updatepanel postback.
protected void UpdatePanel1_Load(object sender, EventArgs e)
{
GridView1.DataBind();
LinqDataSource1.DataBind();
}
I refresh updatepanel each time my selection index changes and it was able to resolve the conflicts.
Hope this helps.
Under:
QuestionModule o = query.First();
You have to add the following command:
db.QuestionModule.Attach(o);