How do you reference a field in the SSRS report inline code

Is there a way to reference ssrs report fields from the ssrs report inline code?

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

There is an error in line 3 of the user code: [BC30469]
A reference to a non-shared element requires a reference to an object.

When I searched Google, I found that you can link to report parameters by adding Report. at the beginning. So I tried this Report.Fields.Program.Value .

This leads to the following error ...

There is an error in line 3 of the user code: [BC30456] "Fields" is not a member of "Microsoft.ReportingServices.ReportProcessing.ExprHostObjectModel.IReportObjectModelProxyForCustomCode".

So ... in general, is there a way to refer to fields from inline code. I realized that I could pass field values ​​for the function itself, but I would prefer to refer directly to the fields.

Set

+4
source share
2 answers

You must pass it as a parameter.

= Code.ToUSD (Fields! StandardCost.Value)

+4
source

You have two more alternatives to passing by parameter, although none of them are very good.

(Beware! After I wrote the next paragraph, I found that the default values ​​from the queries are not supported in local processing mode, so this first solution may not be suitable for you, because it is not for me.)

You can create a hidden report parameter with the default value set from the data set, and then reference it using the Report.Parameters!MyParam.Value . When testing, you should be careful, because (at least in BI studio 2005) the report parameters do not seem to be reliably reinitialized from the database on the "Preview" tab.

Alternatively, you can create a hidden text field in the report with its text set from the data set, and then refer to the text field from the code. In this case, you should pass the ReportItems object as a parameter, but the slight advantage is that it is only one additional parameter. Be sure to enter the parameter strongly when declaring it:

 public Sub MyCustomCode(ri as ReportItems) 

The code will work in BI-studio without a type declaration, but for me it caused errors with the help of the report viewer in the local processing mode if there was no " as ReportItems ".

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

+4
source

All Articles