Click here to Skip to main content
15,888,270 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
On a DataGrideView connect to a MySQL Database, always I undo de changes of a field and I try to update exact as original info, I got an error "Concurrency violation: the UpdateCommand affected 0 of the expected 1 records"

It is a Single user application.

I load the data, I change a field then I put as loaded and ERROR.

my code:
VB
Me.Validate()
Me.TesteBindingSource.EndEdit()
Me.TesteTableAdapter.Update(Me.DataSetMySQL_TESTE.teste)


What I have tried:

If I changed the data in the field everything OK. But if the changes are equal as on loaded then error!
Posted
Updated 3-Mar-20 22:31pm
v2
Comments
[no name] 2-Mar-20 9:48am    
Just have a look right in the CP page under "Related Questions". I think you will find an answer for this. Btw. looks not like a 'real error' it is more that 'Affected Records' returns '0' for the update.
Maciej Los 2-Mar-20 11:51am    
What MySql driver are you using?
RZ50 2-Mar-20 11:59am    
MySQL ODBC 5.1 Driver
Maciej Los 2-Mar-20 12:07pm    
Is there any reason to use ODBC? I'd use MySQL Connector for .NET. See: MySQL - odbc - Should I use Connector/NET or Connector/ODBC to develop my application?[^]
What field causes such of error? I'm guessing that numeric...
RZ50 2-Mar-20 12:45pm    
my table (test) is simple:
pk INT(11)
nome VARCHAR(45)

my CommandText:
UPDATE test SET nome =? WHERE (pk =?)

if I change the wrong record in the DataGridView and reset the initial information and then I change the correct record and when updating it gives me this error and I lose the information of the correct record...

According to our discussion in comments...

Please, read this: MySQL :: Concurrency violation problem on dataset update[^]

There's a suggestion:
Quote:
I ran into this. Switching DOUBLE to type DECIMAL(19,4) fixed it for me. Hope this helps somewhat.
 
Share this answer
 
I found this note "This causes the rows affected count returned to be zero, which the DataAdapter interprets as a concurrency conflict. In this event, a DBConcurrencyException will be thrown."

So in my ODBC Driver I change the option "Return matched rows instead of affected rows" to true and the problem is SOLVED!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900