How do you reference a field in the Embedded Code of an SSRS report

≯℡__Kan透↙ 提交于 2019-12-10 17:13:47

问题


Is there a proper way to reference the fields of a ssrs report from the embedded code of an ssrs report?

When I try to use Fields!Program.Value I get the following error --

There is an error on line 3 of custom code: [BC30469]
Reference to a non-shared member requires an object reference.

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.

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'.

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.

Seth


回答1:


You have to pass it in as a parameter.

=Code.ToUSD(Fields!StandardCost.Value)




回答2:


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.Value syntax. 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.

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 ReportItems object 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:

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.

In either case, this is only really useful for page level data, so functions for use in a table should still take parameters.



来源:https://stackoverflow.com/questions/1400484/how-do-you-reference-a-field-in-the-embedded-code-of-an-ssrs-report

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!