We are trying to use a subreport, but now in Crystal Reports 10 we cannot use the Load() method or the SetParameterValue() method.  How am I supposed to get the DataSource and Parameters set for the subreport if I can't even load it!


Who is Participating?
ebolekConnect With a Mentor Commented:
SetReportParameters_InvestigationReport()  is the twisted version of the code that I posted

That code should help your problem

You can get a reference to the subreport from the main report by using

Opensubreport methoid then

You can use following code to set the parameetrs of the subreport. The report document is the referenced subreport from the open method

//sets the parameter values for main report and sub reports if any
                  CrystalDecisions.CrystalReports.Engine.ParameterFieldDefinition ParameterFieldDefinition;
                  CrystalDecisions.Shared.ParameterDiscreteValue  ParameterDiscreteValue;
                  CrystalDecisions.Shared.ParameterValues  ParameterValues;                              
                  int paramcount;
                  paramcount = this.MyParameterValues.Count;
                  ParameterFieldDefinition = null;
                  string ConversionVariable;
                  ConversionVariable = null;                  
                  for (int i = 0; i != paramcount; i++)//have to put paramcount otherwise hard code it .works
                        ConversionVariable = Convert.ToString(MyReport.DataDefinition.ParameterFields[i].ParameterType);  
                        if (ConversionVariable == "StoreProcedureParameter")       
                              ParameterFieldDefinition = MyReport.DataDefinition.ParameterFields[i];  
                              ParameterValues = new CrystalDecisions.Shared.ParameterValues();
                              ParameterDiscreteValue = new CrystalDecisions.Shared.ParameterDiscreteValue();      
                              ParameterDiscreteValue.Value = this.MyParameterValues[i];      
                  return ParameterFieldDefinition;
jeshbrAuthor Commented:
This is the code I currently have.

//      Set the data source for the sub reports
for (int liSubReport = 0; liSubReport < SubReports.Count; liSubReport++)
      lcSubReport = SubReports[liSubReport].ToString();
      Report.OpenSubreport(lcSubReport).Load(this.GetReportPath() + "rptFeeReportSub1.rpt");

      //      Set the data source
      if (SubReportDataSources != null)

      //      Load the parameters for this sub report
      if (SubReportParameters != null)
            for (int liSRParameter = 0;
                  liSRParameter < SubReportParameters[liSubReport].GetLength(0);
                  lcParameter = SubReportParameters[liSubReport][liSRParameter, 0].ToString();

                  ParameterValues lpvValues = new ParameterValues();
                  ParameterDiscreteValue lpdvParameter = new ParameterDiscreteValue();
                  lpdvParameter.Value = SubReportParameters[liSubReport][liSRParameter, 1];



But after it's all said and done the parameter values and data source for the main and subreport are wrong.
Train for your Pen Testing Engineer Certification

Enroll today in this bundle of courses to gain experience in the logistics of pen testing, Linux fundamentals, vulnerability assessments, detecting live systems, and more! This series, valued at $3,000, is free for Premium members, Team Accounts, and Qualified Experts.

jeshbrAuthor Commented:
The Load() fails by the way!
it fails because when you open the sub report, you try to load
Create a reportdocument variable mysubreport and write this
MySubReport = MyReport.OpenSubreport(MySubReportObject.SubreportName)
jeshbrAuthor Commented:
Even if I do that though it won't let me load it, it gives me this error...Not supported in subreports
Look at this code. This code works.I have done this , You have to cast the object first

CrystalDecisions.CrystalReports.Engine.ReportDocument MySubReport;
                  CrystalDecisions.CrystalReports.Engine.SubreportObject MySubReportObject;
                  foreach (CrystalDecisions.CrystalReports.Engine.ReportObject MyReportObject in MyReport.ReportDefinition.ReportObjects)
                        if (MyReportObject.Kind == CrystalDecisions.Shared.ReportObjectKind.SubreportObject)
                              MySubReportObject = (CrystalDecisions.CrystalReports.Engine.SubreportObject)MyReportObject;
                              if (MySubReportObject.SubreportName != _subreportname)
                                    if (this.ReportName == "InvestigationReport_CoverPage")
                                          int i;
                                          MySubReport = MyReport.OpenSubreport(MySubReportObject.SubreportName);                               
                                          SubReportName = MySubReportObject.SubreportName;
                                          if (MySubReportObject.SubreportName == "InvestigationReport_Vehicles.rpt")
                                                i = 1;
                                                i = 0;
jeshbrAuthor Commented:
What does the code behind SetReportParameters_InvestigationReport() look like?
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.