This strange error was encountered today in Delphi using ADO to update data with MySQL via ODBC: Unable to locate rows for updates. Some values may have changed since the last read.
Think of the solution, and then online search. Some say because there is no primary key, but I have this table, some say there is a default value, I checked, all fields are not the default value, and some say that the first insert and then edit caused, I this is pure edit, POST, no insert, so also does not exist.
Looking for a long time, finally found a similar situation, some people say that if the edit modified data and the original data, the post will be reported this error. I checked, and really, I edit the value of the field assigned to the same as before the change, if a little change, the field value is different, it can be normal post submitted. The solution is to determine whether the value is the same before assigning a value to the field, which is really enough for BT.
The problem is solved, but why is it so? By turning on the ODBC trace Log for analysis, we can probably guess the reason. The following paragraph is a SQL trace log that assigns the same values to all fields:
Bexe 13f4-1118EXIT sqlexecdirectw with return code 0 (sql_success)
HSTMT 0x0362c568
WCHAR * 0x0b774fc8 [-3] "UPDATE ' Test '. ' table1 ' SET ' table1id ' =?, ' contid ' =?, ' NAME ' =?,... ' bkwfid ' =? WHERE ' table1id ' =? and ' contid ' =? And ... and ' Bkwfid ' =?\ 0 "
SDWORD-3
Bexe 13f4-1118 EXIT SQLRowCount with return code 0 (sql_success)
HSTMT 0x0362c568
Sqllen * 0x0018e804 (0)
Notice at this time SQLRowCountreturn Resultsis 0, which means that 0 rows have been updated.
The following is an assignment of a variable SQL trace log:
Bexe 13f4-1118 EXIT sqlexecdirectw with return code 0 (sql_success)
HSTMT 0x0362c568
WCHAR * 0x0b76fec8 [-3] "UPDATE ' Test '. ' table1 ' SET ' table1id ' =?, ' contid ' =?, ' NAME ' =?,... ' bkwfid ' =? WHERE ' table1id ' =? and ' contid ' =? And ... and ' Bkwfid ' =?\ 0 "
SDWORD-3
Bexe 13f4-1118 EXIT SQLRowCount with return code 0 (sql_success)
HSTMT 0x0362c568
Sqllen * 0x0018e804 (1)
The result of the SQLRowCount return is 1, which means that 1 rows have been updated.
Two SQL exactly the same, the difference is only the previous SQL execution after the record content has not changed, and then there is a change! Then for the unchanged situation MySQL tells you that you did not update any records, in fact, you are update a record, just before and after the update results, with no update the same effect, so MySQL returned 0, so ADO think that no update to the data, So that someone else has changed the data, so that the " unable to update the location of the row" error .
Update MySQL with ADO "Unable to locate row for update. Some values may have been changed after the last read "problem resolved