0
votes

I have crystal report with main report and sub report. Main report contains group sections.

I have linked sub report with main report using id. When I preview it on preview tab, both main and sub reports are working and displaying correct data.

But, when I preview it on the viewer with my application, main report data shows correct, but some sub report fields are not visible. I have noticed that, when I put the ID field to view in sub report, it shows a number of records. but only ID field is shown, and other fields are not visible.

I have set two record sets to main report and sub report. it seems records are returning data, but sub report does not shows them. Can anyone please point me in right direction to solve this?

1
where are you passing the ID field to sub report? is it going to Record Selection FormulaSiva

1 Answers

0
votes

Not sure how you are loading your report in the Crystal viewer, but keep in mind that if your report uses subreports, in your code when you are loading the report, you need to also set the data source for each subreport. See the following incomplete code snippet:

//SET DATASOURCE FOR EACH SUBREPORT IN REPORT
foreach (CrystalDecisions.CrystalReports.Engine.Section section in CrystalReportSource2.ReportDocument.ReportDefinition.Sections)
{
    // In each section we need to loop through all the reporting objects
    foreach (CrystalDecisions.CrystalReports.Engine.ReportObject reportObject in section.ReportObjects)
    {
        if (reportObject.Kind == ReportObjectKind.SubreportObject)
        {
            SubreportObject subReport = (SubreportObject)reportObject;
            ReportDocument subDocument = subReport.OpenSubreport(subReport.SubreportName);

            foreach (CrystalDecisions.CrystalReports.Engine.Table table in subDocument.Database.Tables)
            {
                // Cache the logon info block
                TableLogOnInfo logOnInfo = table.LogOnInfo;

                // Set the connection
                logOnInfo.ConnectionInfo = crConnectionInfo;

                // Apply the connection to the table!
                table.ApplyLogOnInfo(logOnInfo);
            }
        }
    }
}