C# – Crystal Reports Subreport Using DataSets

ccrystal-reportsdatasetondemandsubreport

I use Crystal Reports XI with C# Visual Studio 2005.
I am trying to create a subreport from a summary dataset.
A simple example would be Company listing with Employees.
I load the Company dataset (with CompanyId).
I want to create a subreport which is linked by CompanyId whereby the dataset is loaded (obviously) on demand. I can create this subreport if I load all the detail into one monster dataset, but in my real-world implementation this would involve loading millions of detail rows (not an option).

Is there a way I can capture the SubReport event and load the dataset from my database connection? I basically want to intercept the subreport link call to build the dataset myself.

Best Answer

This is simply possible. Create 2 data tables in the xsd dataset you have. Get values for these 2 datatables based on a common ID/key value. Copy one dataset table to the other like

ds2.Tables.Add(ds1.Tables[0].Copy());  

then,

rpt.Load(path + @"Report\Report1.rpt");
rpt.SetDataSource(ds2); //datasource is single
crystalReportViewer.ReportSource = FFrpt;

when ur adding subreport, get the second table as the datasource and its values. add those fields to your subreport, its done !

Regards Shyam

Related Topic