我正在尝试将参数传递给我的报告。我尝试了不同的方法,但每次提示我输入参数值。我读了很多类似的问题,但对我没什么用。
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);
答案 0 :(得分: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);