2017-03-27 59 views
1

我試圖通過從WinForm的水晶報表參數,但我得到這個錯誤缺少的參數值在水晶報表

缺少參數值

我的代碼:

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中檢查了參數的名字,這也很好。我檢查了價值,它也獲得了正確的價值。

所以請幫助我找出我錯在哪裏。

感謝

回答

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; 
+0

所以要我刪除'ParameterFields paramfields =新ParameterFields();''直到= rptvwrcash.ParameterFieldInfo paramfields;'? – mark

+0

只是先評論你的舊代碼,然後嘗試按照新的代碼 –

+0

仍然是相同的錯誤 – mark