Updating a record

Discussion of open issues, suggestions and bugs regarding MyDAC (Data Access Components for MySQL) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
Rober Watson
Posts: 7
Joined: Tue 02 Sep 2008 16:14

Updating a record

Post by Rober Watson » Wed 19 Nov 2008 18:53

I'm have a table with one field and I'm trying
to edit it. Multiple records can have the same
value in this field (the field is named "Name").
Am using this code:

with DM.myType do
begin
Edit;
fieldByName('Name').AsString:=edType.Text;
// Post;
UpDateRecord;
ApplyUpdates;
edType.Text:='';
end;

As long as I edit a record which is the only record
with that "Name" value it works. If I try to edit
a record which is one of several with the same
"Name" value, it fails with this exception error message

"Update failed. Found 3 records."

As you can see I have tried Post and UpdateRecord
with the same result. Can anyone help?

TIA,
Bob

swierzbicki
Posts: 451
Joined: Wed 19 Jan 2005 09:59

Post by swierzbicki » Thu 20 Nov 2008 13:02

You are answering your question :) :
I have a table with one field [...] multiple records can have the same value
When posting Datas, MyDAC will generate a SQL query like that :

Code: Select all

Update TABLENAME 
Set FieldName = :FieldName
Where
Fieldname = :FieldName
MySQL server will returns that 3 records has been updated. MyDAC expect 1 record to be updated and not 3

To change that either :
- modify your table structure by adding an AutoIc Field , make it your primary key (best solutionin your case)
- set the MyQuery.options.StructUpdate to false

Post Reply