Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Set datasource of Sub Report of a Sub Report

Status
Not open for further replies.

mattybat

Programmer
Oct 14, 2003
3
GB
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
 
My understanding of CR for .Net is that it is a subset of CR 9. Now, it's possible that there are feature differences between the two and that, perhaps, you can do a thing or two in .Net that you can't do in CR 9, but Crystal 9 does not allow nested subreports. And that is such an important feature, it's hard to imagine that you could do it in .Net but not in 9. When you go into the first subreport in the Crystal Designer, can you see the nested subreport object and open it up as well?
 
I just done 'Edit Subreport' from the main report to edit the first subreport and that subreport dosen't contain the second subreport as I was expecting.

Thanks a lot for pointing out this short fall of CR.
 
It is quite fair to call a lack of nested subreports a shortfall. Many people would love to have that feature in Crystal.

However, often people use subreports when they don't need to. This may not be your case, but people who are inexperienced in writing SQL statements to collect data (here I'm assuming the report is running against a database like SQL Server or Oracle) often use subreports as a means to collect data that can be more easily collected through either joins or correlated subqueries in a SQL statement. Or, if need be, one can write a stored procedure that uses temp tables and "massages" the data to look the way you need it to. As a .Net developer, you have all those tools available to you via ADO. So perhaps the way to address your problem is to create an ADO recordset that contains more data than you are currenlty getting and then passing the expanded recordset to your report. Then again, maybe not. I don't know you're situation. I'm just passing this along because it has been my experience.
 
To FVTrainer
Is it possible to enter a correlated subquery in Crystal?
I am an oracle user and am used to creating correlated subqueris in SQL+, but I did not think this was possible in Crystal.
BTW I do not have DBA or developer accesss to the database so setting up temporary tables (although doable) would not be within my security privledges.
Thanks,
 
If you're a SQL person, create a View and pass the script along to the DBA.

Crystal won't go for the correlated subquery, but you can embed the entire SQL into the report, I do so in CR 8.5 by using an ADO connection and pasting the query in.

-k
 
If you are using Crystal 9, you can create a command object as your report datasource (which is the ability to use a SQL statement you create) which would allow you to do correlated subqueries.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top