Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

display data drom a linked ADOTable

Status
Not open for further replies.

MLNorton

Programmer
Nov 15, 2009
134
US
I have a Delphi XE2 program with two Access linked ADOTables. Table 1 contains the names and addresses and Table 2 contains Transactions for each individual in Table 1.
How can I select a a name from Table 1 and display in a DBGrid the Transactions for that individual?
 
Further Information.

I know how to display the data by using two DBGrids but I cannot get it to work.

I have linked the two Access tables, MEM_ID one (Table1) to many (Table2)

I have set the Table 2 Master Fields to MEM_ID and the IndexFieldName to MEM_ID. Both DBGrids display the Table 1 data. I cannot display the Table 2 data in DBGrid 2.

What am I missing?
 
You'll need to set up the two ADOTables and have one TDataSource for each ADOTable.

1) Set the first Datasource.DataSet property to ADOTable1 and repeat for the second pointing to ADOTable2.

2) For ADOTable2, set it's mastersource property to ADOTable1 and set the masterfields to MEM_ID (if that is the only column of the key for ADOTable1)

3) Drop two DBGrids on your form.

4) Set DBGrid1's datasource property to Datasource1 (which should point to ADOTable1) and DBGrid2's datasource property to Datasource2 which should point to ADOTable2.

5) Double click DBGrid1, click the Add All Fields button. You should only see the fields associated with Table1. Repeat for DBGrid2. BTW, you can alter which columns are shown (by deleting the ones you don't want (such as MEM_ID), and also alter the DBGrid's Title row, by selecting a field and using the object inspector.

6) Add code to open ADOTable1, than ADOTable2 in FormCreate. DBGrid2 should automatically only show the associated rows for the selected row in DBGrid1.
 
Followed instructions exactly and still both DBgrid1 and DBGrid2 display the DBGrid1 data.
What next?
 
If both grids are showing the same data then both grids are looking at either the same datasource or both datasources are looking at the same table.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top