I am not sure if the question title is clear enough, please feel free to edit it.
Basically, I have two DB grids which reflect two database tables, each grid showing one.
When the user selects a row in the first table (let's call it oders
), I want to update the second with details of any rows matching a column of the selected row of the first table.
Say, for instance that table orders
has a column customer_id
and I want to populate the second table (let's call it order_details
) with details of all orders from that customer, one order per row.
I can connect up 2 @ datasource, query and connection to the two TDbGrid
s, but I am stuck as to how to code order_details
SQL.
The SQL for orders
is just SELECT * from orders
, but the other?
I want something like SELECT * from order_details WHERE cutomer_id=<orderQuery>.currentRow.FieldByName("customer_id").AsInteger
- but I don't know how to do that ...
Can someone help me with some Delphi code?
Also, once I set up that relationship, will selecting a new row in the orders
DB grid automatically update the order_details
DB grid? Or do I need to add code for that.
P.s I know that there is no books
tag anymore (more's the pity), but can someone recommend a good book which explains the fundamentals of programming DB aware controls? I obviously need one. Thanks
here's
a tutorial for this topic. Maybethis part
might be interesting for you, maybe not. – TLama