如何在水晶报表中向子报表发送参数

How to send parameters to Subreport in Crystal Reports(如何在水晶报表中向子报表发送参数)
本文介绍了如何在水晶报表中向子报表发送参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 VS 2008.

Using VS 2008.

我有两个存储过程,一个用于获取主报告的数据,另一个用于获取子报告的数据,并且两个 SP 都使用相同的参数 QuoteID.

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.

我已使用 ReportDocument 向主报告发送参数.但我不知道如何向 SubReport 发送参数.

I have send parameter to main report using ReportDocument. But I am not aware how to send parameters to SubReport.

我使用报告文档的 setparameter 方法尝试了许多不同的方法,该方法也将子报告名称作为参数.但它没有.

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

下面是我用过的代码

    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 + @"
ptQuotationReport.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); 
    } 

向子报表发送参数

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

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

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

没有任何效果.我已经为此浪费了两天时间.[SD_SalesOrderReport;1] 主 SP 和 [SD_GetBatchReportDetails;1] 子报表 SP.

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.

推荐答案

经过多次尝试,我终于解决了.也许这对其他人有帮助.我在Main和SubReport中使用了相同的参数Name,使用下面的代码来设置它的参数

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());

这篇关于如何在水晶报表中向子报表发送参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

DispatcherQueue null when trying to update Ui property in ViewModel(尝试更新ViewModel中的Ui属性时DispatcherQueue为空)
Drawing over all windows on multiple monitors(在多个监视器上绘制所有窗口)
Programmatically show the desktop(以编程方式显示桌面)
c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
LINQ many-to-many relationship, how to write a correct WHERE clause?(LINQ多对多关系,如何写一个正确的WHERE子句?)