I am new to Crystal Reports. I have designed a Crystal Report by following this link: Crystal Report with SQL Stored Procedure Parameter and Visual Studio What I need to do is pass different ID's (Input value of the SP) to the SP that I connected with the Crystal Report.
This is the code I have which passes the ID 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 whenever I click the button it asks for the ID...
You can pass parameter values to a crystal report programmatically using ReportDocument. DataDefinition. ParameterFields member, which represents a collection of parameters associated with a report. Before you use ParameterFields, you must import CrystalReport.
Go to Report menu>> Select Expert >> Record. Select the field for which the filter is to be applied. Click on OK. Now, refresh the report and enter multiple values seperated by comma(,).
Parameters are used to take user inputs before the report is generated. User has to answer the prompt before the report is generated and the report output depends on the response of the user for the parameter value.
To set parameter on crystal I always do it this way:
ReportDocument reportDocument = new ReportDocument();
reportDocument.Load(reportPath);
reportDocument.SetParameterValue("@id", QuotationID);
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);
this returns you back a filestream that you can open from the aspx page.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With