5

How to use multiple subreport in a main report in ... - SAP Community

 7 months ago
source link: https://community.sap.com/t5/technology-q-a/how-to-use-multiple-subreport-in-a-main-report-in-asp-net/qaq-p/13594860
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

How to use multiple subreport in a main report in asp.net

Nat064

Discoverer

Monday

Hello,

I have two subreport included in a main report. Each subreport contain a datasource.

When I try to setdatasource in subreport from asp.net c#, it return an error which say Missing parameter values.

My subreports are on demand and my main report doesn't have any datasource



Thanks in adance

Accepted Solutions (0)

Answers (2)

DellSC

Active Contributor

Thursday

Your subreports are coming  back blank because setting the datasource at the subreport level doesn't work.  In both the main report and any subreports, you have to walk through the tables and set the datasource on the tables themselves.

The code for setting the login for the data in the subreports should look something like this:

private void ConfigureCrystalReports()
{
  northwindCustomersReport = new ReportDocument();
  string reportPath = Application.StartupPath + "\\" + "NorthwindCustomers.rpt";
  northwindCustomersReport.Load(reportPath);

  //Build the ConnectionInfo used for assigning credentials for the data
  ConnectionInfo connectionInfo = new ConnectionInfo();
  connectionInfo.ServerName = "localhost";
  connectionInfo.DatabaseName = "Northwind";
  connectionInfo.IntegratedSecurity = true;
            
  crystalReportViewer.ReportSource = northwindCustomersReport;
  //Set credentials for the main report
  SetDBLogonForReport(connectionInfo, northwindCustomersReport); 
  //Set credentials for the subreports
  SetDBLogonForSubreports(connectionInfo, northwindCustomersReport);
}

private void SetDBLogonForReport(ConnectionInfo connectionInfo, 
     ReportDocument reportDocument)
{
  Tables tables = reportDocument.Database.Tables;
  foreach (CrystalDecisions.CrystalReports.Engine.Table table in tables)
  {
    TableLogOnInfo tableLogonInfo = table.LogOnInfo;
    tableLogonInfo.ConnectionInfo = connectionInfo;
    table.ApplyLogOnInfo(tableLogonInfo);
  }
}

private void SetDBLogonForSubreports(ConnectionInfo connectionInfo, 
    ReportDocument reportDocument)
{
  Sections sections = reportDocument.ReportDefinition.Sections;
  foreach (Section section in sections)
  {
    ReportObjects reportObjects = section.ReportObjects;
    foreach (ReportObject reportObject in reportObjects)
    {
      if (reportObject.Kind == ReportObjectKind.SubreportObject)
      {
        SubreportObject subreportObject = (SubreportObject)reportObject;
        ReportDocument subReportDocument = 
               subreportObject.OpenSubreport(subreportObject.SubreportName);
        SetDBLogonForReport(connectionInfo, subReportDocument);
      }
    }
  }

This code was taken from the sample code that can be downloaded from the "SAP Crystal Reports .NET SDK Tutorial Sample Code" link on the Crystal for VS Help page.

-Dell


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK