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

我是水晶报告的新手.我按照这个链接 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 …

解决方法

要在水晶上设置参数,我总是这样做:
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页面打开的文件流.

相关文章

这篇文章主要讲解了“WPF如何实现带筛选功能的DataGrid”,文...
本篇内容介绍了“基于WPF如何实现3D画廊动画效果”的有关知识...
Some samples are below for ASP.Net web form controls:(fr...
问题描述: 对于未定义为 System.String 的列,唯一有效的值...
最近用到了CalendarExtender,结果不知道为什么发生了错位,...
ASP.NET 2.0 page lifecyle ASP.NET 2.0 event sequence cha...