Page 1 of 1

How do I update multiple tables from using TMyQuery?

Posted: Thu 23 Aug 2007 06:51
by robbiem
This strikes me as a really obvious question:

I have a query:

select a.keyfield,a.field1,a.field2,b.anotherfield
from firsttable a left join secondtable b on b.keyfield=a.keyfield

I wish to use a data control to edit the result (let us say, Datagrid)
The TMyQuery component behaves very well as far as updating the fields in firsttable, but does not update secondtable (fair enough).

What I want to on Posting is a) work out if anotherfield has been modified, and b) generate a sql to update secondtable if so.

Which event should I trap on? How would I tell the dataset that I've handled the update for it?

OnUpdateRecord would seem obvious, but it doesn't seem to actually trigger.

BeforeUpdateRecord?

Posted: Thu 23 Aug 2007 11:44
by Antaeus
You can the UpdatingTable property of your TMyQuery to specify for which of two tables in the query will be generated an update statement.
If you want to update both tables simultaneously, you should provide appropriate commands to SQLInsert, SQLUpdate, SQLDelete properties of you TMyQuery object.
If your handlers are complicated, you can attach TMyQuery, or TMyCommand components through the TMyUpdateSQL component to execute update commands. See the UpdateSQL demo included in MyDAC General demo for details. You can find MyDAC General demo in the MyDAC_InstDir\Demos\MyDACDemo directory.
MyDAC_InstDir is the MyDAC installation directory on your computer.