visual-studio 您如何引用 SSRS 报告的嵌入代码中的字段
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1400484/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do you reference a field in the Embedded Code of an SSRS report
提问by Seth Spearman
Is there a proper way to reference the fields of a ssrs report from the embedded code of an ssrs report?
是否有正确的方法可以从 ssrs 报告的嵌入代码中引用 ssrs 报告的字段?
When I try to use Fields!Program.ValueI get the following error --
当我尝试使用时Fields!Program.Value,出现以下错误——
There is an error on line 3 of custom code: [BC30469]
Reference to a non-shared member requires an object reference.
自定义代码的第 3 行有错误:[BC30469]
对非共享成员的引用需要对象引用。
Upon googling I found you could reference the Parameters of a report by prepending Report.at the beginning. So I tried this Report.Fields.Program.Value.
通过谷歌搜索,我发现您可以通过Report.在开头添加来引用报告的参数。所以我尝试了这个Report.Fields.Program.Value。
That results in the following error...
这导致以下错误...
There is an error on line 3 of custom code: [BC30456] 'Fields' is not a member of 'Microsoft.ReportingServices.ReportProcessing.ExprHostObjectModel.IReportObjectModelProxyForCustomCode'.
自定义代码的第 3 行出现错误:[BC30456]“字段”不是“Microsoft.ReportingServices.ReportProcessing.ExprHostObjectModel.IReportObjectModelProxyForCustomCode”的成员。
So... in summary, is there a way to reference the fields from the embedded code. I figured out I could pass the field vals to the function itself but I would prefer to reference the fields directly.
所以......总而言之,有没有办法从嵌入的代码中引用字段。我发现我可以将字段 vals 传递给函数本身,但我更愿意直接引用这些字段。
Seth
赛斯
采纳答案by gbn
回答by OlduwanSteve
You do have two other alternatives to passing by parameter, though neither is very pretty.
除了通过参数传递之外,您还有其他两种选择,但都不是很漂亮。
(Beware! After I wrote the following paragraph I discovered defaults from queries are not supported in local processing mode so this first solution may not be viable for you as it was not for me.)
(注意!在我写下以下段落后,我发现本地处理模式不支持查询的默认值,因此第一个解决方案可能对您不可行,因为它不适合我。)
You can create a hidden report parameter with a default value set from a dataset, then reference this with the Report.Parameters!MyParam.Valuesyntax. You have to be careful when testing this, as (at least in BI studio 2005) the report parameters don't seem to get reliably re-initialised from the DB in the Preview tab.
您可以使用从数据集设置的默认值创建隐藏报表参数,然后使用Report.Parameters!MyParam.Value语法引用它。测试时必须小心,因为(至少在 BI studio 2005 中)报告参数似乎无法从预览选项卡中的数据库可靠地重新初始化。
Alternatively you can create a hidden textbox on the report with its text set from a dataset, and then reference the textbox from code. In this case you have to pass the ReportItemsobject as a parameter, but the slight advantage is that it is only ever one extra parameter. Be sure to strongly type the parameter when declaring it:
或者,您可以使用来自数据集的文本集在报表上创建一个隐藏的文本框,然后从代码中引用该文本框。在这种情况下,您必须将ReportItems对象作为参数传递,但有一点好处是它只是一个额外的参数。声明时一定要强类型参数:
public Sub MyCustomCode(ri as ReportItems)
The code will work in BI studio without the type declaration but for me it caused errors with the report viewer control in local processing mode if 'as ReportItems' was not present.
该代码将在没有类型声明的 BI Studio 中工作,但对我来说,如果“ as ReportItems”不存在,它会导致本地处理模式下的报表查看器控件出错。
In either case, this is only really useful for page level data, so functions for use in a table should still take parameters.
在任何一种情况下,这仅对页面级数据真正有用,因此在表中使用的函数仍应接受参数。

