Page 1 of 1

Updating a record

Posted: Wed 19 Nov 2008 18:53
by Rober Watson
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

Posted: Thu 20 Nov 2008 13:02
by swierzbicki
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