2

我正在尝试将参数传递给我的报告。我尝试了不同的方法,但每次它都会提示我输入参数值。我阅读了大量类似的问题,但对我没有任何帮助。

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);
4

1 回答 1

1

可以使用 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);
于 2014-03-04T06:44:43.387 回答