Click to Rate and Give Feedback
MSDN
MSDN Library
SQL Server
SQL Server 2008
Reporting Services
Development
 How to: Add Code to a Report
Community Content
In this section
Statistics Annotations (0)
Collapse All/Expand All Collapse All
Other versions are also available for the following:
SQL Server 2008 Books Online (October 2009)
How to: Add Code to a Report (Reporting Services)

In any expression, you can call your own custom code. You can provide code in the following two ways:

  1. In Design view, right-click the design surface outside the border of the report and click Report Properties.

  2. Click Code.

  3. In Custom code, type the code. Errors in the code produce warnings when the report runs. The following example creates a custom function named ChangeWord that replaces the word "Bike" with "Bicycle".

    Public Function ChangeWord(ByVal s As String) As String
       Dim strBuilder As New System.Text.StringBuilder(s)
       If s.Contains("Bike") Then
          strBuilder.Replace("Bike", "Bicycle")
          Return strBuilder.ToString()
          Else : Return s
       End If
    End Function
  4. The following example shows how to pass a dataset field named Category to this function in an expression:

    =Code.ChangeWord(Fields!Category.Value)

    If you add this expression to a table cell that displays category values, whenever the word "Bike" is in the dataset field for that row, the table cell value displays the word "Bicycle" instead.

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks | Privacy Statement | Site Feedback
Page view tracker