Page 1 of 1

Problem with dbgrid which contains JOIN statement

Posted: Fri 24 Nov 2006 09:37
by gilbert3
I created 2 tables which contains some relation data. This two tables are joined with LEFT JOIN statement with Core Lab's "MyQuerry" component and DataSource , DbGrid included in Delphi 7. Fields are displaying correctly, but I'm wordering how to update second table, which contains ID relation with first table. I just wanted to update fields directly on dbGrid, but of course nothing happens in tables. Which property MyQuerry or DBGrid or maybe DataSource should I use to update fields in second table linked with LEFT JOIN.
Thank you very, very much.

Posted: Fri 24 Nov 2006 09:55
by Antaeus
Try to assign the name of the second table to the MyQuery.UpdatingTable property. You can find the information about this property in the MyDAC help.

Posted: Thu 30 Nov 2006 09:10
by gilbert3
Antaeus wrote:Try to assign the name of the second table to the MyQuery.UpdatingTable property. You can find the information about this property in the MyDAC help.
Let me explain it - my code:

MyQuerry1.SQL:='select first_table.first_field, first_table.second_field, second_table.first_field from first_table left join second_table on first_table.id = second_table.first_table_id';


As we know how works "left join".: this SQL will display all records from first_table even second_table contains empty fields.

While UpdatingTable is selected od "second_table" MyDac displaying message 0 fields updated. It's happen because second_table is totally empty. It doesn't contain any data, just structure. I would like to fill second_table with data from first_table and from user with dbgrid.

I'll try to do something with master, detail. If somebody has some hints - thanks very much.

Posted: Thu 30 Nov 2006 15:17
by Antaeus
Solution with Master/Detail relationship should be better than a single query with the JOIN clause. Please see the MasterDetail demo of MyDAC. You can find this demo in %MyDAC%\Demos\MasterDetail directory.
%MyDac% is the MyDAC installation path on your computer.