Sending parameters to Subreport in Crystal Reports RRS feed

  • Question

  • User-1713825770 posted


    I have two stored procedures, one used to get data for the main report and other for Sub report.I have send parameter to main report
    using ReportDocument. But I am not aware how to send parameters to SubReport.

    I tried many diff ways using the reportdocument's setparameter method which also takes subreport name as argument.But it didn't.

    Can anyone let me know how to send params to Subreport.

    Need code snippet in C#

    Friday, February 22, 2013 9:58 PM

All replies

  • User-1713825770 posted


    I have tried the below code

                    AccountsPayableMaster objAPM = new AccountsPayableMaster();
                    QuotationReport obj = new QuotationReport();
                    objReportDocument.Load(Application.StartupPath + @"\rptQuotationReport.rpt");
                    obj.crysQuotationReport.LogOnInfo = objAPM.ConnectionDetails("SD_SalesOrderReport;1"); // Main Report SP
                    obj.crysQuotationReport.LogOnInfo = objAPM.ConnectionDetails("SD_GetBatchReportDetails;1"); /// SubReport SP
                    objReportDocument.SetParameterValue("@QuoteID", ValQuoteID);
                    objReportDocument.Subreports["Sub.rpt"].SetParameterValue("@QuoteBatchID", ValQuoteID); // Throws Error
                   //objReportDocument.SetParameterValue("@QuoteBatchID", ValQuoteID,"Sub.rpt");
                    objReportDocument.SetParameterValue("Type", Type);
                    string[] Print = objAPM.GetPrintDetails();
                    SetPrintParameters(objReportDocument, Print);
                    objReportDocument.ExportToDisk(ExportFormatType.PortableDocFormat, FilePath);
                    obj.crysQuotationReport.ReportSource = objReportDocument;
                   // Number++;
                catch (Exception ex)

    Above code throws an error object reference not set to an instance where the Subreport parameter is being Set.

    I have tried to set the the SubReport Parameter by using below methods

    1) objReportDocument.Subreports["Sub.rpt"].SetParameterValue("@QuoteBatchID", ValQuoteID); // Throws Error
    2)  objReportDocument.SetParameterValue("@QuoteBatchID", ValQuoteID,"Sub.rpt");
    3) objReportDocument.Subreports["Sub"].SetParameterValue("@QuoteBatchID", ValQuoteID); // Throws Error 4) objReportDocument.SetParameterValue("@QuoteBatchID", ValQuoteID,"Sub");

    I dont understand where am i going wrong.
    Friday, February 22, 2013 10:49 PM