How to send parameters to Subreport in Crystal Reports

不想你离开。 提交于 2020-01-13 03:22:47

问题


Using VS 2008.

I have two stored procedures, one used to get data for the main report and other for Sub report and both the SP's use the same parameter QuoteID.

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.

Below is the code I have used

    string Type = gvQuotationDetails.Rows[QuoteIndex].Cells["Type"].EditedFormattedValue.ToString();

    FilePath = ConfigurationManager.AppSettings["EMP_IMG_PATH"].ToString() + "\\" + ValQuoteID.ToString() + ".pdf";

    DeleteExistingFile(FilePath);

    try
    {
        AccountsPayableMaster objAPM = new AccountsPayableMaster();
        QuotationReport obj = new QuotationReport();
        objReportDocument.Load(Application.StartupPath + @"\rptQuotationReport.rpt");
        obj.crysQuotationReport.LogOnInfo = objAPM.ConnectionDetails("SD_SalesOrderReport;1");
        obj.crysQuotationReport.LogOnInfo = objAPM.ConnectionDetails("SD_GetBatchReportDetails;1");
        obj.crysQuotationReport.ReportSource = objReportDocument;
        objReportDocument.SetParameterValue("@QuoteID", ValQuoteID);
        objReportDocument.SetParameterValue("Type", Type);
        //objReportDocument.Subreports[Application.StartupPath + @"\BatchSubReport.rpt"].SetParameterValue("@QuoteID", ValQuoteID);
        //objReportDocument.Subreports["BatchReport.rpt"].SetParameterValue("@QuoteID", ValQuoteID);           

        string[] Print = objAPM.GetPrintDetails();

        SetPrintParameters(objReportDocument, Print);

        obj.Show();

        objReportDocument.ExportToDisk(ExportFormatType.PortableDocFormat, FilePath);
    }

    catch (Exception ex)
    {
        MessageBox.Show(ex.Message); 
    } 

Sending parameter to Subreport

//objReportDocument.Subreports[Application.StartupPath + @"\BatchSubReport.rpt"].SetParameterValue("@QuoteID", ValQuoteID);

//objReportDocument.Subreports["BatchReport.rpt"].SetParameterValue("@QuoteID", ValQuoteID);              

////objReportDocument.SetParameterValue("@QuoteID", ValQuoteID,"BatchReport.rpt);

nothing worked.I have already wasted two days on this. [SD_SalesOrderReport;1] main SP and [SD_GetBatchReportDetails;1] subreport SP.

It would be great if someone can provide a solution for this.If there are some changes to be made in designed please share images.Thank you.


回答1:


Finally after lot of trails, I have solved it.May be this will be helpful to others.I have used the same parameter Name for Main and SubReport, used below code to set its parameter

objReportDocument.SetParameterValue("@QuoteID", ValQuoteID,objReportDocument.Subreports[0].Name.ToString());



回答2:


Well, this is really helpful for me as my problem has been solved with the following code.

rd.SetParameterValue("TotalVisits", totalVisits, rd.Subreports[0].Name.ToString());

rd.SetParameterValue("GrandTotal", grandTotalPaymentType, rd.Subreports[1].Name.ToString());


来源:https://stackoverflow.com/questions/15037550/how-to-send-parameters-to-subreport-in-crystal-reports

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!