How to Access and Read Report Parameters in Custom Code using SQL Server Reporting Services
Microsoft SQL Server Reporting Services enables report developers pass values as parameters in order to use within the report. SQL Server Reporting Services from the beginning SSRS 2000, 2005 and the recent version SSRS 2008 has the Custom Code extensibility option for developers to consume methods and objects from custom assemblies or enables report developers to build their own functions to use in the report layout.
If you are using and developing custom code in your reports, then you might probably require the need of accessing the report parameters from functions in custom code sections.
If you try to access and use the report parameters as you might be doing in the Data pane of your report like "Parameters!BaseDate.Value" then you will get the following error message:
An error occurred during local report processing.
The definition of the report '/report_name' is invalid.
There is an error on line 182 of custom code: [BC30469] Reference to a non-shared member requires an object reference.
Actually the correct way and the correct syntax to reach, read report parameters, accessing to report parameter is "Report.Parameters!BaseDate.Value".
You can get readonly values of reporting services report parameters by adding the "Report." object which exposes the Parameters collection to the custom code section.
Sample Function in Custom Code which access to Report Parameter
Here is the source code of a sample custom code function which access report parameters and use report parameter value within the function.
Public Function GetColumnNameAsDate(ByVal DayId As Short) As String
try
Dim FromDate as datetime
FromDate = Report.Parameters!BaseDate.Value
return CType(DATEADD(DateInterval.Day, DayId - 1,FromDate), string)
catch ex as System.Exception
Return ex.message
end try
End Function
