我正在使用Visual Studio 2012,Window Form Application。 我使用存储过程创建了一个Crystal报表,该报表接受三个参数 i-e @DateFrom,@ DateTo和@District,我必须从c#代码中传递这些参数。
我有以下代码只接受一个不多的参数,请帮帮我
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();
}
我哪里出错?
答案 0 :(得分:1)
加载报告文档后,您只需要致电:
reportDocument.SetParameterValue("DateFrom", dateFrom);
reportDocument.SetParameterValue("DateTo", dateTo);
reportDocument.SetParameterValue("District", district);
修改强>
// 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);
这只是将参数值设置为报告。
答案 1 :(得分:0)
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;