Crystal Report: Setting values to subreport parameters using C#
Report Part
We create a report and then we press to the New Subreport button ( or
). Then, on the new window, we write the name of the subreport and we click on Ok button.
After calling the subrepot we click on Report Wizard button. We follow all the steps (or press on the Finish butten when you can) and we place the subreport on the nursemaid report.
Done that, we take a double click on the subreport to get in it. Being in, we create the parameters we want (as we explain in this post). In the example, only one:
Created all the parameters, we close the subreport and save the nursemaid report. We’ve finished this step.
Code Part
In this part, we’re going to need these assemblies in our project:
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Web;
To proceed we are going to create a crystal report “in code”:
ReportDocument rptDoc = new ReportDocument();
rptDoc.Load(pathReport);
After that we should “connect” the report to the data base:
ConnectionInfo cInfo = new ConnectionInfo();
cInfo.UserID = "user";
cInfo.Password = "passwor";
cInfo.ServerName = "datasource";
ConectaReport(cInfo, rptDoc);
And now, we assign the subparameter name and value:
rptDoc.SetParameterValue("paramOne", "this is the subparam value", "subReport");
That’s all!
Tags: crystal, how, howto, parameters, pass, report, subreport, to, value

