C#中Crystal Report中缺少参数值

时间:2017-03-27 09:25:57

标签: 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);

我在Crystal Report中检查了参数的名称,这也没关系。我检查了价值,它也得到了正确的价值。

所以请帮我找出错误的地方。

由于

2 个答案:

答案 0 :(得分:1)

报告参数如下所示:

CRPT.SetParameterValue("smonth", Servercls.month);
CRPT.SetParameterValue("sday", Servercls.day);
CRPT.SetParameterValue("datevalue", Servercls.Datevalue);
Report_Viewer.ReportSource = CRPT;

有关详细信息,请参阅此Report Parameter

尝试这种方式:

ReportDocument  CRPT = new ReportDocument();
ParameterFields param = new ParameterFields();
ParameterDiscreteValue paramdesc = new ParameterDiscreteValue();
ParameterField paramfield = new ParameterField();
paramfield.Name = "type";

String APPPATH = Environment.CurrentDirectory + "\\CrystalReport1.rpt";
CRPT.Load(APPPATH);
param = CRPT.ParameterFields;
CRPT.ParameterFields.Add(paramfield);
param["type"].CurrentValues.Clear();
paramdecs.Value = "this is you crystal report parameter value value";
param["type"].CurrentValues.Add(paramdecs);

rv.ReportSource = CRPT;

答案 1 :(得分:0)

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

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