Passing parameter in CRYSTAL REPORT via C # in asp.net

I am new to crystal reporting. I developed a crystal report by following this Crystal Report link with the SQL stored procedure parameter and Visual Studio Actually, I need to pass a different identifier (SP input value) to the SP that I connected to the Crystal report.

This is the code that I pass to the 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; } 

But when I click the button, it asks for an identifier ... enter image description here

+7
c # sql-server crystal-reports
source share
1 answer

To set the parameter on the chip, I always do it like this:

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

if you want to convert your report to 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); 

this returns you a return stream that can be opened from an aspx page.

+11
source share

All Articles