views:

287

answers:

2

Hi,

I need a little help with ClientDatasets in Delphi.

What I want to achieve is a grid showing customers, where one of the columns shows the number of orders for each customer. I put a ClientDataset on a form and load Customers.xml from Delphi demo-data. Another ClienDataset is loaded with orders.xml. Relatively simple, I can define an aggregate on the orders CDS showing the total amount per customer (or the count). (See Cary Jensens article on this: http://edn.embarcadero.com/article/29272) The problem is getting this aggregate result from orders dataset into the customer dataset.

It is kind of an reverse lookup, since there is a 1-n relationship between customers and orders, not an n-1 as normally in lookup scenarios.

Any ideas ?

Søren

+4  A: 

Maybe you could define a calculated field in the customers dataset which would simply take the value of the aggregated field in the orders dataset.

TOndrej
Hi TOndrej,that is a feasible solution, I think I wil go with that.Thanks a lot for your suggestion.
TheRoadrunner
A: 

Have you tried to do a Master (Customers) - Detail (Orders) relation?
It's not a lookup situation.

François
Hi Francois,The Master-detail relation is incompatible with the aggregate function, since it redefines the Index-definitions on the orders dataset.
TheRoadrunner