在asp.net中传递参数的水晶报表通过C#
我是新来的晶体report.I已经通过以下链接水晶报表与SQL存储过程参数和Visual Studio
其实我需要通过不同的ID(SP的输入值),我与Crystal报表连接SP。
I am new to crystal report.I have designed the crystal report by following this link Crystal Report with SQL Stored Procedure Parameter and Visual Studio Actually i need to pass different ID(Input value of the SP) to the SP that i connected with the Crystal report.
这是code是我传递的ID来水晶报表:
This is the Code that i am Passing the ID to 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按钮...
But when ever i click the button it asking the ID ...
要设置晶体参数,我总是做这种方式:
To set parameter on crystal I always do it this way:
ReportDocument reportDocument = new ReportDocument();
reportDocument.Load(reportPath);
reportDocument.SetParameterValue("@id", QuotationID);
如果您希望您的报表转换为PDF格式:
if you want to convert your report to a 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);
这将返回回FILESTREAM,你可以从aspx页面打开。
this returns you back a filestream that you can open from the aspx page.