During Update facing exception Row not found or changes
Whenever I try to update the new values in gridview(It's not a datagridview) I am getting an exception "Row not found or changed".(if the values are not changed it works properly) I have tried various solution like set updatecheck to never,delete and redrag table from database, double check for nullable nothing works. I am using Linq to SQL datasource and 4.5 .Net framework.
ASP.NET
C#
-
Karen Payne MVP 35,036 Reputation points
2022-06-24T11:24:36.363+00:00 Your question requires clarity, how is the gridview (unsure what you mean if this is a DataGridView or not) being load, how is the data source configured and what is
linqdatasource
??? -
Monika Patil 1 Reputation point
2022-06-24T11:54:05.373+00:00 It's not a datagridview and LinqDataSource is control which enables you to use LINQ in an ASP.NET Web page by setting properties in markup text. I am using Linq to SQL datasource
-
Karen Payne MVP 35,036 Reputation points
2022-06-24T12:02:51.42+00:00 Then edit your original question and place that information in to it rather than as a reply to me.
-
Lan Huang-MSFT 25,711 Reputation points • Microsoft Vendor
2022-06-27T07:29:48.16+00:00 Hi @Monika Patil ,
Can you provide details on your code, database design, etc.?
Make sure the DBML and database definitions match.
You could try using the KeepChanges option to refresh the object immediately before updating it.db.Refresh(System.Data.Linq.RefreshMode.KeepChanges, employee);
Best regards,
Lan Huang -
Monika Patil 1 Reputation point
2022-06-27T14:54:30.153+00:00 Thanks for the reply .I have checked dbml and database defination matches correctly.
Actually I am new to this can you guid me where to use refresh object code that you mentioned.
Thanks.
I am using following code
protected void DetailsDataSource_Updating(object sender, LinqDataSourceUpdateEventArgs e)
{
Product originalProduct = (Product)e.OriginalObject;
Product newProduct = (Product)e.NewObject;if (originalProduct.Category != newProduct.Category) { new product.ModifyBy=User.Identity.Name; }
}
-
Lan Huang-MSFT 25,711 Reputation points • Microsoft Vendor
2022-06-28T07:39:22.62+00:00 Hi @Monika Patil ,
The Refresh method is for the database context, not your code.
Make sure not to update non-nullable fields with null values.
Can you provide all the code and database design? so that we can better help you solve the problem.
Best regards,
Lan Huang -
Monika Patil 1 Reputation point
2022-06-29T07:51:05.637+00:00 PFA
These are the 3 files that I am using 215968-sodapdf-converted-listcs.pdf216004-sodapdf-converted-listaspx.pdf215956-dbcontext-1.pdf -
Lan Huang-MSFT 25,711 Reputation points • Microsoft Vendor
2022-06-30T09:45:39.2+00:00 Hi @Monika Patil ,
Apart from the update method, did the code you provided run successfully?
I found a lot of small errors in your code, like the screenshot below, probably copied and pasted by mistake.
Which line of code does it show reporting the error(Row not found or changed)? Can you post screenshots?
Best regards,
Lan Huang -
Monika Patil 1 Reputation point
2022-07-01T09:57:42.887+00:00 I have corrected that part and still I am getting that exception . And it's not showing for any line the update stops working and when I check it from backend using emlah error it's showing the exception message 'Row not found or changed'
-
Lan Huang-MSFT 25,711 Reputation points • Microsoft Vendor
2022-07-04T09:48:20.497+00:00 Hi @Monika Patil ,
The main reason for this problem may be that the data types of all fields in O/R-Designer do not match the data types in the SQL table.
Since the information you provided cannot reproduce your problem, you need to provide more detailed information. Maybe you can provide a similar small example.
Best regards,
Lan Huang
Sign in to comment