SQL Server administration and T-SQL development, Web Programming with ASP.NET, HTML5 and Javascript, Windows Phone 8 app development, SAP Smartforms and ABAP Programming, Windows 7, Visual Studio and MS Office software
Development resources, articles, tutorials, code samples, tools and downloads for ASP.Net, SQL Server, Reporting Services, T-SQL, Windows, AWS, SAP HANA and ABAP


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

access report parameters from custom code

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
Code


SQL Server

SQL Server 2019 Installation
download SQL Server 2019
download SQL Server 2017
download SQL Server 2016
download SQL Server 2014
download SQL Server 2012
MacOS ve SQL Server 2019


Copyright © 2004 - 2021 Eralper YILMAZ. All rights reserved.