如何在报表查看器中添加参数? [英] how to add parameters in report viewer?

查看:340
本文介绍了如何在报表查看器中添加参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

HY!我在Visual Studio 2010中有一个表单应用程序,我想用报表查看器创建一个报表并添加一些参数。我试图从代码中添加参数,但它没有工作。我有这个错误:

Tablix'Tablix1'的FilterExpression表达式指的是'datastart'字段。报告项目表达式只能引用当前数据集范围内的字段,或者如果在聚合内部,则指定指定的数据集范围。
Report2.rdlc:error rsParameterReference:Tablix'Tablix1'的FilterValue表达式指的是不存在的报告参数'datastart'。



在我的代码中执行此操作:

pre $ private $ void SetReportParameters )
{
ReportParameter [] parameters = new ReportParameter [2];
parameters [0] = new ReportParameter(datastart,dateTimePickerStartRaport.Text);
参数[1] =新ReportParameter(dataStop,dateTimePickerStopRaport.Text);
this.reportViewer1.LocalReport.SetParameters(parameters);
}

并且在调用此方法后,在报表查看器上进行刷新

  reportViewer1.RefreshReport(); 

我也查看其他论坛,并且看到必须将这些参数添加到报告中,但我没有理解我该怎么做。我还尝试在报表的属性窗口中添加一些值为
$ b

  =参数!datastart.Value $ b的过滤器$ b  

但这也没有用。

解决方案

你得到的错误是因为你试图像字段一样指定你的参数。在表达式设计器中,您有一个称为参数的特殊类别。从那里你可以访问你的参数。
语法为 =参数![FieldName] .Value 。例如 = Parameters!datastart.Value 。

另外,请注意参数必须在参数下的报告数据窗口。它与您用于声明记录集的窗口相同,但也有一个特殊的参数类别。也有一些数据类型的选项,如果参数的规范是强制性的。


HY! I have a form application in visual studio 2010 and I want to create a report with report viewer and to add some parameters. I tried to add parameters from code but it didn`t work. I have this error:

FilterExpression expression for the tablix ‘Tablix1’ refers to the field ‘datastart’. Report item expressions can only refer to fields within the current dataset scope or, if inside an aggregate, the specified dataset scope. Report2.rdlc : error rsParameterReference: The FilterValue expression for the tablix ‘Tablix1’ refers to a non-existing report parameter ‘datastart’.

In my code a do this:

 private void SetReportParameters()
    {
        ReportParameter[] parameters = new ReportParameter[2];
        parameters[0] = new ReportParameter("datastart", dateTimePickerStartRaport.Text);
        parameters[1] = new ReportParameter("dataStop", dateTimePickerStopRaport.Text);
        this.reportViewer1.LocalReport.SetParameters(parameters);
    }

and after calling this method a make a refresh on the report viewer

 reportViewer1.RefreshReport();           

I also look at other forums and I saw that I have to add the parameters to the report, but I didn`t manage out how must I do this. I also tried to add, in the properties windows of the report, some filters with value

  =Parameters!datastart.Value     

but this also didn`t work.

解决方案

The error you get is because you try to specify your parameter like a field. In the expression-designer you have a special category called "Parameters". From there you can access your parameters. The syntax is =Parameters![FieldName].Value. In your case for example =Parameters!datastart.Value.

Additionaly, note that the parameters must be declared in the "Report Data"-window under "Parameters". Its the same window as you use to declare your recordsets, however there is also a special category for parameters. There are also some options for the datatype and if specification of the parameter is mandatory.

这篇关于如何在报表查看器中添加参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆