Reputation: 79
I am using Visual Studio 2012 , Window Form Application . I have created a report with Crystal report using stored procedure which accepts three parameters i-e @DateFrom, @DateTo, and @District, i have to pass these parameters from c# code.
I have the following code which accepts only one parameter not multiple, please help me
private void btn_Preview_Click(object sender, EventArgs e)
{
string parm_From = "01-07-2014";
string param_To = "30-06-2015";
string param_District = "DistrictName";
ReportDocument reportDocument = new ReportDocument();
ParameterField paramField = new ParameterField();
ParameterFields paramFields = new ParameterFields();
ParameterDiscreteValue paramDiscreteValue = new ParameterDiscreteValue();
paramField.CurrentValues.Add(parm_From);
paramFields.Add(paramField);
crystalReportViewer1.ParameterFieldInfo = paramFields;
reportDocument.Load(@"\GenPensionReport.rpt");
crystalReportViewer1.ReportSource = reportDocument;
crystalReportViewer1.Refresh();
}
where i am going wrong?
Upvotes: 1
Views: 6207
Reputation: 11
CrystalReport1 objRpt = new CrystalReport1();
objRpt.SetDataSource(ds);
ParameterFields pfield = new ParameterFields();
ParameterField ptitle = new ParameterField();
ParameterField ptitle1 = new ParameterField();
ParameterField ptitle2 = new ParameterField();
ParameterDiscreteValue pvalue;
ParameterDiscreteValue pvalue1;
ParameterDiscreteValue pvalue2;
ptitle.ParameterFieldName = "pdate";//pdate is a crystal report parameter name
ptitle.CurrentValues.Clear();
pvalue = new ParameterDiscreteValue();
ptitle.CurrentValues.Add(pvalue);
pvalue.Value = txtcolor.Text.ToString();
pfield.Add(ptitle);
ptitle1.ParameterFieldName = "no";//no is a crystal report parameter name
ptitle1.CurrentValues.Clear();
pvalue1 = new ParameterDiscreteValue();
ptitle1.CurrentValues.Add(pvalue1);
pvalue1.Value=txtno.Text.ToString();
pfield.Add(ptitle1);
ptitle2.ParameterFieldName = "date";//date is a crystal report parameter name
ptitle2.CurrentValues.Clear();
pvalue2 = new ParameterDiscreteValue();
ptitle2.CurrentValues.Add(pvalue2);
pvalue2.Value = textBox1.Text.ToString();
pfield.Add(ptitle2);
crystalReportViewer1.ParameterFieldInfo = pfield;
Upvotes: 0
Reputation: 5858
After you load the report document, you just need to call:
reportDocument.SetParameterValue("DateFrom", dateFrom);
reportDocument.SetParameterValue("DateTo", dateTo);
reportDocument.SetParameterValue("District", district);
EDIT
// The names must match what Crystal expects, So if they contain @ you must include them.
reportDocument.SetParameterValue("@DateFrom", dateFrom);
reportDocument.SetParameterValue("@DateTo", dateTo);
reportDocument.SetParameterValue("@District", district);
This simply sets the parameter values to the report.
Upvotes: 1