C# 中水晶报表中缺少参数值

mar*_*ark 1 c# parameters crystal-reports

我试图将参数从 Winform 传递到 Crystal Report,但收到此错误

缺少参数值

我的代码:

PrintCashReport cashreport = new PrintCashReport();
rptvwrcash.ReportSource = cashreport;

ParameterFields paramfields = new ParameterFields();
ParameterField type = new ParameterField();
type.Name = "type";

ParameterDiscreteValue dvtype = new ParameterDiscreteValue();
dvtype.Value = DailySalesReportBL.typeofrpt;
type.CurrentValues.Add(dvtype);
paramfields.Add(type);

rptvwrcash.ParameterFieldInfo = paramfields;

//PrintCashReport cashreport = new PrintCashReport();
cashreport.SetDataSource(ds);
cashreport.SetParameterValue("type", DailySalesReportBL.typeofrpt);

//rptvwrcash.ReportSource = cashreport;
System.Drawing.Printing.PrintDocument printDocument = new System.Drawing.Printing.PrintDocument();
cashreport.PrintOptions.PrinterName = printDocument.PrinterSettings.PrinterName;
cashreport.PrintOptions.PrinterName = "EPSON TM-T88V Receipt";
cashreport.PrintToPrinter(1, false, 0, 0);
Run Code Online (Sandbox Code Playgroud)

我检查了水晶报表中的参数名称,也没有问题。我已经检查了值,它也得到了正确的值。

所以请帮我找出我哪里错了。

谢谢

小智 5

您应该在“cashreport.SetDataSource(ds)”之后设置“paramfields.Add(....”!

否则,参数将被“SetDataSource...”覆盖。