Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 928
Seth Spearman Avatar asked Sep 09 '09 15:09

Seth Spearman


People also ask

What is embedded data source in SSRS?

An embedded data source, also known as a report-specific data source, is a data connection that's saved in the report definition. Embedded data source connection information can be used only by the report in which it's embedded. To define and manage embedded data sources, use the Data Source Properties dialog box.

How do I add assembly reference in SSRS?

To add an assembly reference to a report In Design view, right-click the design surface outside the border of the report and click Report Properties. Click References. In Add or remove assemblies, click Add and then click the ellipsis button to browse to the assembly.


2 Answers

You have to pass it in as a parameter.

=Code.ToUSD(Fields!StandardCost.Value)

like image 70
gbn Avatar answered Oct 01 '22 00:10

gbn


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.

like image 35
OlduwanSteve Avatar answered Oct 01 '22 00:10

OlduwanSteve