Crystal Report参数再次不起作用

本文关键字:不起作用 参数 Report Crystal | 更新日期: 2023-09-27 17:58:57

我正试图将一个参数传递给我的报告。我尝试过不同的方法,但每次都会提示我输入参数值。我读过很多类似的问题,但对我来说都不起作用

P_REQUEST_ID是一个静态数字参数字段,用于过滤报告中的数据。

这是我的代码:

// creating report
var reportDocument = new ReportDocument();
reportDocument.Load("ReportRequestPrice.rpt");
// creating report form 
var dialog = new FormReport();
// not working
var paramFields = new ParameterFields();
var paramField = new ParameterField();
var paramDiscreteValue = new ParameterDiscreteValue();
paramField.Name = "P_REQUEST_ID";
paramDiscreteValue.Value = 1;
// not working
// paramDiscreteValue.Value = "1";
paramField.CurrentValues.Add(paramDiscreteValue);
paramFields.Add(paramField);
dialog.reportViewer.ParameterFieldInfo = paramFields;
/*
// not working
var param = new ParameterDiscreteValue();
param.Value = 1;
reportDocument.ParameterFields["P_REQUEST_ID"].CurrentValues.Add(param);
// not working
//reportDocument.ParameterFields[0].CurrentValues.Add(param);
*/
// setting datasource
reportDocument.SetDataSource(printshopDS);
reportDocument.Subreports[0].SetDataSource(printshopDS);
dialog.reportViewer.ReportSource = reportDocument;            
dialog.ShowDialog(this);

Crystal Report参数再次不起作用

可以使用Crystal Reports for Visual Studio 2005复制此问题。解决方法是先设置CrystalReportViewer的ReportSource属性,然后通过属性ParameterFieldInfo设置参数值。因此,您的代码应该是:

// creating report
var reportDocument = new ReportDocument();
reportDocument.Load("ReportRequestPrice.rpt");
// creating report form 
var dialog = new FormReport();
dialog.reportViewer.ReportSource = reportDocument;            
// not working
var paramFields = new ParameterFields();
var paramField = new ParameterField();
var paramDiscreteValue = new ParameterDiscreteValue();
paramField.Name = "P_REQUEST_ID";
paramDiscreteValue.Value = 1;
// not working
// paramDiscreteValue.Value = "1";
paramField.CurrentValues.Add(paramDiscreteValue);
paramFields.Add(paramField);
dialog.reportViewer.ParameterFieldInfo = paramFields;

// setting datasource
reportDocument.SetDataSource(printshopDS);
reportDocument.Subreports[0].SetDataSource(printshopDS);

dialog.ShowDialog(this);