【问题标题】:Passing parameters to CRYSTAL REPORTS via C# in asp.net在 asp.net 中通过 C# 将参数传递给 CRYSTAL REPORTS
【发布时间】:2013-11-19 05:42:54
【问题描述】:

我是 Crystal Reports 的新手。我通过以下链接设计了一个水晶报表:Crystal Report with SQL Stored Procedure Parameter and Visual Studio 我需要做的是将不同的 ID(SP 的输入值)传递给我与 Crystal Report 连接的 SP。

这是我将 ID 传递给 Crystal Report 的代码:

        protected void Button1_Click(object sender, EventArgs e)
        {
        string QuotationID = ViewState["QUOTATION_ID"].ToString();
        ReportDocument reportDocument = new ReportDocument();
        ParameterField paramField = new ParameterField();
        ParameterFields paramFields = new ParameterFields();
        ParameterDiscreteValue paramDiscreteValue = new ParameterDiscreteValue();


       
        paramField.Name = "@id";


        paramDiscreteValue.Value = QuotationID;

        paramField.CurrentValues.Add(paramDiscreteValue);
        paramFields.Add(paramField);

        
        paramFields.Add(paramField);

        CrystalReportViewer1.ParameterFieldInfo = paramFields;

        string reportPath = Server.MapPath("~/CrystalReport.rpt");

        reportDocument.Load(reportPath);

       
        CrystalReportViewer1.ReportSource = reportDocument;
        }

但每当我点击按钮时,它都会要求输入 ID...

【问题讨论】:

    标签: c# asp.net sql-server crystal-reports


    【解决方案1】:

    要在水晶上设置参数,我总是这样做:

    ReportDocument reportDocument = new ReportDocument();
    reportDocument.Load(reportPath);
    reportDocument.SetParameterValue("@id", QuotationID);
    

    如果您想将报告转换为 pdf:

    var exportOptions = reportDocument.ExportOptions;
    exportOptions.ExportDestinationType = ExportDestinationType.NoDestination;
    exportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;
    var req = new ExportRequestContext {ExportInfo = exportOptions};
    var stream = reportDocument.FormatEngine.ExportToStream(req);
    

    这会返回一个文件流,您可以从 aspx 页面打开该文件流。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-09-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-01-07
      相关资源
      最近更新 更多