如何将多个参数从C#传递到水晶报告

时间:2016-01-06 20:27:51

标签: c# crystal-reports

我用这个鳕鱼将参数传递给CR,但是不能传递多个参数! 如何更改此代码以将多个参数从C#传递到水晶报表?

ReportDocument cryRpt1 = new ReportDocument();
cryRpt1.Load("C:\\Users\\BilgiSoft\\Desktop\\RPTLetter1.rpt");

ParameterFieldDefinitions crParameterFieldDefinitions;
ParameterFieldDefinition crParameterFieldDefinition;
ParameterValues crParameterValues = new ParameterValues();
ParameterDiscreteValue crParameterDiscreteValue = new ParameterDiscreteValue();

crParameterDiscreteValue.Value = comboBox1.Text;
crParameterFieldDefinitions = cryRpt1.DataDefinition.ParameterFields;
crParameterFieldDefinition = crParameterFieldDefinitions["My Parameter"];
crParameterValues = crParameterFieldDefinition.CurrentValues;

crParameterValues.Clear();
crParameterValues.Add(crParameterDiscreteValue);
crParameterFieldDefinition.ApplyCurrentValues(crParameterValues);

crystalReportViewer1.ReportSource = cryRpt1;
crystalReportViewer1.Refresh();

1 个答案:

答案 0 :(得分:0)

以下是一个例子:

ReportDocument cryRpt1 = new ReportDocument();
cryRpt1.Load("C:\\Users\\BilgiSoft\\Desktop\\RPTLetter1.rpt");

ParameterValues crParameterValues = new ParameterValues();
//Add first param
ParameterFieldDefinitions crParameterFieldDefinitions = cryRpt1.DataDefinition.ParameterFields;
crParameterFieldDefinition = crParameterFieldDefinitions["My Parameter"];
crParameterValues = crParameterFieldDefinition.CurrentValues;
ParameterDiscreteValue crParameterDiscreteValue = new ParameterDiscreteValue();
crParameterDiscreteValue.Value = comboBox1.Text;
crParameterValues.Add(crParameterDiscreteValue);

//add second param
ParameterFieldDefinitions crParameterFieldDefinitions = cryRpt1.DataDefinition.ParameterFields;
crParameterFieldDefinition = crParameterFieldDefinitions["My Parameter 2"];
crParameterValues = crParameterFieldDefinition.CurrentValues;
ParameterDiscreteValue crParameterDiscreteValue = new ParameterDiscreteValue();
crParameterDiscreteValue.Value = comboBox2.Text;
crParameterValues.Add(crParameterDiscreteValue);

crystalReportViewer1.ReportSource = cryRpt1;
crystalReportViewer1.Refresh();