I have a crystal report with a bunch of parameterized fields that are being filled by code and displayed through CRViewer. I need to add a few sections in here to execute a query to return a dataset and display this in the same report. I am not sure if the best way to do this with a subreport. I am trying to add a subreport and then set the datasource of the subreport to my dataset, but I cannot get it to work.
Is this even the proper way or I am just doing something wrong?
Any help would be appreciated.
EDIT:
Example of what I am looking to do.
Lets say there is a customers table. I have FirstName LastName as parametirized fields displayed on the form along with address and basic customer information.
I want to place a subreport showing all orders this customer has made on the SAME report. The is an association table with multiple orders possible.
The report is being placed in a class that can be called by a VB.NET app. Therefore I cannot create the dataconnection for the subreport in the UI (or maybe I can and pass params later).
I am successfully populating the parameterized field by doing the following:
Dim myRpt As New RunReport.RunReport
myRpt.Load("myReport.rpt")
'Set Labels
myRpt.SetParameterValue("@FirstName", strFirstName)
CrystalReportViewer1.ReportSource = myRpt
A customerID would be available as well on to bind if needed to the association rows.
This will be one report I just need to display the subreport section to handle all possible orders. This is the part I am having the issue with.
Are you setting your main report’s datasource like this?
If so, setting it on the subreport might look like this:
I’ve read your update above and think I understand what you are going for. See if this works for you:
1) Create the main report. Give is whatever selection criteria you want (ex. CustName or CustID)
2) Create the sub report. Give it the selection selection criteria you want (ex. CustID)
3) Once you have inserted the subreport into the main report, right-click on the subreport object/box in the designer and pick “Change Subreport Links”
4) In the “Fields to link to” box, pick the value from the main report that will drive the subreport. (Ex. CustID)
5) In the “Subreport parameter field to use” dropdown, select the subreport parameter field that you want to link to the main report (Ex. CustID)
When you run the report, the subreport should only show data for the record that is displayed in the main report.
If those steps don’t get you what you are looking for, please describe what functionality is missing.
P.S.: If you are trying to pull data only once (instead of once for main and again for sub), my question would be: why?