Open the Report Properties dialog box from the Visual Studio Designer and select the References tab. The next step is to add a reference to your new assembly to your report. To create the class library for this example, do the following: The first step is to create a new class library with a shared method (static for C# folks). So how do you create and embed your own assembly into an SSRS report? It’s pretty simple.
VISUAL STUDIO 2019 SSRS CODE
As stated earlier, SSRS embedded code is limited to using only Visual Basic code. The second reason is that you might prefer writing code in C#, C++, or some other. You cannot access embedded code from multiple reports. You can use external assemblies in multiple reports. Why would you want to create an external assembly for your reports? Two reasons come to mind. This section discusses creating an external assembly and using it in your reports. Adding Custom AssembliesĪs explained earlier, SSRS provides the ability to add code to your reports using two mechanisms: direct embedding of Visual Basic code or linking to external assemblies. Previewing your report should now show the number of orders for each customer record. Select the System.Data and the System.Xml assemblies from the provided dialog box. To add a reference to your report, open the Report Properties dialog box from the Visual Studio Designer and select the References tab. To fix this issue you need to add references to the System.Data and System.XML assemblies. This signifies that a reference to the assembly containing the class is missing. When you select the Preview tab you see a compilation error in the Error List tab of the Visual Studio designer (Figure 4). From the Layout tab add a new column and set its Value property to =Code.GetCustomerOrderCount(Fields!CustomerID.Value). After adding the code from Listing 1 to the report you can test it by adding a new column to the report. The code in Listing 1 demonstrates accessing data from SQL Server and returning it to the report.
To add more advanced capabilities (data access for instance) you must add references to the desired assemblies. You can type or paste code directly into the XML file.įigure 3: XML source code showing section.īy default the SSRS custom code mechanism is limited to the most basic functions of the. Search for the element in the provided XML source code (Figure 3). In the Solution Explorer, right-click the report and select View Code from the provided pop-up menu. If you don’t like editing code using small dialog boxes, you have another mechanism for editing embedded report code. The output for the CompanyName displays in upper case. In the Company Name field, change the Value property from =Fields!CompanyName.Value to =Code.CoDeDemo(Fields!CompanyName.Value). To use your new function, switch to the Layout tab in the Report Designer. You can call your new function from your report by using the Code function provided via the SSRS expression syntax. Enter the following code into the Custom Code field and click OK: Function CoDeDemo_() Embed code into reports by selecting Report | Report Properties… from the Visual Studio shell, and then select the Code tab in the provided dialog box. SSRS provides the capability of embedding Visual Basic. NET code directly in your reports or you can add externally created and compiled assemblies. SSRS provides two mechanisms for adding code to your report: You can embed Visual Basic.
Now that you have created a simple report you can add custom code. To create new reports, you’ll perform the following tasks.įigure 1: Customer report in Design mode.įigure 2: Customer report in Preview mode. This article uses data from the SQL Server sample database Northwind. This article demonstrates adding custom code to SQL Server Reporting Services reports. SSRS gives developers the ability to add custom code to their report layouts. While the expression system is quite powerful it is not suitable for all applications. SSRS has a well-designed data access engine, a great set of layout tools, and an excellent expression system for creating complex formulas. SQL Server Reporting Services versions 20 (SSRS) has many powerful features.