C # Code:
PrivatevoidButton4_Click (Objectsender, EventArgs e)
{
Print master and slave table data
StringFILE = Application.startuppath @ "\masterdetail.frx";
Rptmasterdetail.load (file);To load a report template file
DataSet ds = DAL. Getmasterdetaildata ();Fetching report data
Rptmasterdetail.registerdata (ds. Tables[0], "tb_so");Registering a data source, primary table
Rptmasterdetail.registerdata (ds. Tables[1], "Tb_sos");Registering a data source from a table
//
Registering a DataSet directly is OK, but you must specify a table name for Dataset.tables!
Fastreport is a DataTable object that is followed by a table name.
//
Rptmasterdetail.registerdata (DS);
//
Bind data Source to Databand (primary table data)
Databand Masterband = Rptmasterdetail.findobject ("Data1")AsDataband;
Masterband.datasource = Rptmasterdetail.getdatasource ("Tb_so");Main Table
Bind a data source to Databand (detail data)
Databand Detailband = Rptmasterdetail.findobject ("Data2")AsDataband;
Detailband.datasource = Rptmasterdetail.getdatasource ("Tb_sos"); List
Important!! Set the primary foreign key relationship for the schedule!
Detailband.relation =NewRelation ();
DetailBand.Relation.ParentColumns =NewString[] {"SONO"};
DetailBand.Relation.ParentDataSource = Rptmasterdetail.getdatasource ("Tb_so"); Main Table
DetailBand.Relation.ChildColumns = new string[] {"SONO"};
DetailBand.Relation.ChildDataSource = Rptmasterdetail.getdatasource ("Tb_sos"); //Schedule
//Prepare to work, display report preview form
Rptmasterdetail.prepare ();
Rptmasterdetail.showprepared (True, this );
}
Specific steps:
1. Load the report template file, load ().
2. Get the report data through the DAL layer, return the dataset type, containing two data tables (main Table tb_so, Schedule Tb_sos).
3. Registerdata, register the data source. Important
4. Bind the data source to the Databand object, named Data1 bind the main table, DATA2 bind the schedule. Important
5. Set the primary foreign key relationship for the schedule Databand. Important
6. Prepare the report and display the preview form.
Fastreport for. NET Data bonding