Page 1 of 1

tuniquery edit error when select 1 field

Posted: Thu 10 Nov 2011 13:49
by lao
unidac version 3.70.0.19
delphi 2007

Hello,
i have a table with 3 fields(field1, field2, field3)
i do
select field2 from mytable

myquery.edit;
myquery['field2'] := 'new value';
myquery.post;
i have an error: Update failed. Found x records.
and all records in mytable with old value of field2 are updated, not only current field.

if i do
select * from mytable, no problem.
any idea?

Posted: Thu 10 Nov 2011 14:46
by AndreyZ
Hello,

To avoid such problem, you have to include Primary Key fields into your SELECT statement. In this case the UPDATE statement will use Primary Key fields and only one record will be updated. You can set the TUniTable.Debug property to True. The Debug property is used to display the exact statement that is being executed, all its parameters' values, and the type of parameters. This will help you to understand the cause of this problem. Note that to make the Debug property work, you should add the UniDacVcl unit to the uses clause of any unit in your project.