cancel
Showing results for 
Search instead for 
Did you mean: 

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

Nat064
Discoverer
0 Kudos

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

DellSC
Active Contributor
0 Kudos
Please post the code you're using to set the data source for the subreports.

Accepted Solutions (0)

Answers (2)

Answers (2)

DellSC
Active Contributor
0 Kudos

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

Nat064
Discoverer
0 Kudos

Now I've moved on a bit. 

This is how I load my mainReport which contains two subreports

ReportDocument reportDocument = new ReportDocument();

reportDocument.Load(Server.MapPath("~/Documents/DocumentGlobal.rpt"));

After that, I set the datasource for each subreport like this : 

DataTable dt = CreateAttPres();

reportDocument.Subreports[0].SetDataSource(dt);

DataTable dt = CreateAttRemb);

reportDocument.Subreports[1].SetDataSource(dt);

 

But when I try to generate them, they are empty 

 

DonWilliams
Active Contributor
0 Kudos

You have set the reports data source to a dataset, doesn't appear the data set has any data in it.

Use the same code as what Dell showed you and your report should start working.

For more info and sample try my Parameter test app, single step through it to see what is happening:

ow-to-parameters-in-crystal-reports-for-visual-studio-net