Hi All,
I have a report that contains a subreport, and that subreport also contains a subreport. The problem is that I can't figure out how to set the datasource of
the sub report in the sub report. I am using Crystal Reports.Net (VS2003) and am setting the datasource of the reports to datatables.
My Datalayer is returning the correct data the the datasource of both the main report and the subreport of the main report are being set successfully.
Below is the code I am using:
## CODE BEGIN ##
ReportDocument report = null;
ReportDocument subreport = null;
SubreportObject subreportObject = null;
DataTable dt1 = Datalayer.GetReportData1();
DataTable dt2 = Datalayer.GetReportData2();
DataTable dt3 = Datalayer.GetReportData3();
report = new ProgramReport();
report.SetDataSource( dt1 );
// setup the subreport
subreportObject = report.ReportDefinition.ReportObjects[ "Subreport" ] as SubreportObject;
subreport = report.OpenSubreport( subreportObject.SubreportName );
subreport.SetDataSource( dt2 );
// setup the subreport of the subreport
// the code below is how i thought you would get the subreport of the subreport and set the datasource
ReportDocument subsubreport = null;
SubreportObject subsubreportObject = null;
// the below line results in an 'CrystalDecisions.CrystalReports.Engine.InvalidArgumentException: Invalid report object name.'
subsubreportObject = subreport.ReportDefinition.ReportObjects[ "SubreportSubreport" ] as SubreportObject;
subsubreport = subreport.OpenSubreport( subsubreportObject.SubreportName );
subsubreport.SetDataSource( dt3 );
## CODE END ##
It would be much appreciated if someone could point me in the right direction.
Thanks,
Matthew
I have a report that contains a subreport, and that subreport also contains a subreport. The problem is that I can't figure out how to set the datasource of
the sub report in the sub report. I am using Crystal Reports.Net (VS2003) and am setting the datasource of the reports to datatables.
My Datalayer is returning the correct data the the datasource of both the main report and the subreport of the main report are being set successfully.
Below is the code I am using:
## CODE BEGIN ##
ReportDocument report = null;
ReportDocument subreport = null;
SubreportObject subreportObject = null;
DataTable dt1 = Datalayer.GetReportData1();
DataTable dt2 = Datalayer.GetReportData2();
DataTable dt3 = Datalayer.GetReportData3();
report = new ProgramReport();
report.SetDataSource( dt1 );
// setup the subreport
subreportObject = report.ReportDefinition.ReportObjects[ "Subreport" ] as SubreportObject;
subreport = report.OpenSubreport( subreportObject.SubreportName );
subreport.SetDataSource( dt2 );
// setup the subreport of the subreport
// the code below is how i thought you would get the subreport of the subreport and set the datasource
ReportDocument subsubreport = null;
SubreportObject subsubreportObject = null;
// the below line results in an 'CrystalDecisions.CrystalReports.Engine.InvalidArgumentException: Invalid report object name.'
subsubreportObject = subreport.ReportDefinition.ReportObjects[ "SubreportSubreport" ] as SubreportObject;
subsubreport = subreport.OpenSubreport( subsubreportObject.SubreportName );
subsubreport.SetDataSource( dt3 );
## CODE END ##
It would be much appreciated if someone could point me in the right direction.
Thanks,
Matthew