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