System.Data.Linq.ChangeConflictException: Row not found or changed

后端 未结 19 2761
生来不讨喜
生来不讨喜 2020-12-07 22:21

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

19条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-07 23:10

    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.

提交回复
热议问题