delphidatasourcefastreporttclientdataset

Create relationship between two query delphi


I have two table Country and City (country_id is PK in Country table and country_id is FK in City table).

Which component use to create relation between two query for fast report.

our

Which structure should be:

  1. Query 2. Client Data set .... 3. ? 4.?

Solution

  • This is usually called a Master-Detail relationship between the datasets involved.

    In Delphi, you set one up by connecting the Detail dataset to a TDataSource whose dataset is the connected to the Master dataset. You can do this on the server side (i.e between the two queries, using the DataSource property of the Detail or between two clientdatasets using the MasterSource property of the.Detail. When doing it on the server side, you write the SQL for the query as a parameterised query, with the parameter being one whose value matches the Master's PK as in

      Select * from mydetailtable where masterid = :masterid
    

    Once a Master-Detail relationship has been set up between two datasets, it should work with virtually any report generator, FastReports included.

    See e.g. http://docwiki.embarcadero.com/RADStudio/Rio/en/Setting_Up_Master-Detail_Linked_Relationships which talks about this in terms of DBExpress components, but the principle is applicable to other Delphi dataset components.