Concurrency violation: the UpdateCommand affected 0 records.

  • Thread starter Thread starter JRH
  • Start date Start date
J

JRH

Wanted to post my scenario about this error message for others to
benefit from...

I was getting this error on a certain table and could not figure out
why to save my life. I use the same data access strategy for all DA
objects and was not having the problem with any other object/table.
Here's what was going on:

The Update proc generated by the Data Adapter Configuration Wizard
creates 2 fields for every one... one for the current value and one
for the "Original" value.

I had a table with these columns:

Logon_ID
Username
Password
Original_Username
Original_Password

You should start to see the problem now. What happened was the DACW
creates a parameter for the Username called "Original_Username", then
I ALSO had the real field name "Original_Username". ADO.NET got
confused and thought that the field had changed because it was looking
at the wrong field, and it threw the "Concurrency violation: the
UpdateCommand affected 0 records." error. I changed my field names to
O_Username and O_Password and it was fixed.

I liked to never found this. It was a real problem for a couple days.
So, I wanted to share this info. I've had other problems like this
stemming from using certain words for/in field names, so I've resolved
to, at my next project, come up with a prefix to put in front of all
column names. It will be kind of clumbsy when working directly in the
Db (SQL), but the names can then be abstracted (the prefix can be
stripped) in the business objects. At least it will avoid weird
problems like this.
 
Back
Top