我用这个鳕鱼将参数传递给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();
答案 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();