首页 文章

通过asp.net中的C#将参数传递给CRYSTAL REPORT

提问于
浏览
7

我是晶体报告的新手 . 我按照这个链接设计了水晶报告Crystal Report with SQL Stored Procedure Parameter and Visual Studio实际上我需要将不同的ID(SP的输入值)传递给我与Crystal报告连接的SP .

这是我将ID传递给水晶报告的代码:

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 ...
enter image description here

1 回答

  • 11

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

    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页面打开的文件流 .

相关问题