Monday, 16 July 2012

How to do a simple RDLC report using Visual Studio

RDLC (Report Definition Language Client-side)

  1. What is RDLC Reporting service?
RDLC stands for Report Definition Language Client-side. RDLC can be run completely client-side in the ReportViewer control. This removes the need for a Reporting Services instance, and even removes the need for any database connection whatsoever; but it adds the requirement that the data that is needed in the report has to be provided manually. RDLC reports do not store information about how to get data. RDLC reports can be executed directly by the ReportViewer control.

DL files are created by the SQL Server 2005 version of Report Designer. RDLC files are created by the Visual Studio 2008 version of Report Designer.RDL and RDLC formats have the same XML schema. However, in RDLC files, some values (such as query text) are allowed to be empty, which means that they are not immediately ready to be published to a Report Server. The missing values can be entered by opening the RDLC file using the SQL Server 2005 version of Report Designer. (You have to rename .rdlc to .rdl first.).
RDL files are fully compatible with the ReportViewer control runtime. However, RDL files do not contain some information that the design-time of the ReportViewer control depends on for automatically generating data-binding code. By manually binding data, RDL files can be used in the ReportViewer control. New! See also the RDL Viewer sample program.
The ReportViewer control does not contain any logic for connecting to databases or executing queries. By separating out such logic, the ReportViewer has been made compatible with all data sources, including non-database data sources. However this means that when an RDL file is used by the ReportViewer control, the SQL related information in the RDL file is simply ignored by the control. It is the host application's responsibility to connect to databases, execute queries and supply data to the ReportViewer control in the form of ADO.NET Data Tables.
RDL Much better development experience, more flexibility if you need to use some advanced features like scheduling, ad-hoc reporting, etc... RDLC (Local reports): Better control over the data before sending it to the report (easier to validate or manipulate the data prior to sending it to the report). It has much easier deployment and no need for an instance of Reporting Services.
One HUGE drawback with local reports is a known memory leak that can severely affect performance if your clients will be running numerous large reports. This is supposed to be addressed with the new VS2010 version of the report viewer.

  1. How to create a RDLC report in VS 2008?
Step1: Creating Client Report Definition (.rdlc) Files.
There are many ways for creating rdlc files. Follow any of these methods for creating rdlc file Create a new client report definition (.rdlc) file in Visual Studio. Convert an existing RDL file to rdlc or create rdlc file programmatically. I am dealing here only on creating new rdlc from VS.
Select “Add new item” and select report/report wizard
Selecting report will add an empty rdlc file whereas wizard will lead you to create a report with data connection.
MyReport.rdlc is added to the solution explorer.
IF you are using report wizard, follow the following steps..

Create connection string
Save connection string to web.config file
Choose your stored procedure/table/query
Add fields to the report
Complete the wizard

Step2: Creating a dataset.
Select “add new item” to add a dataset to the project
Add the new dataset to the app_code folder
Step3: Drag Table Adapter & Use the configuration wizard to configure the dataset.
Select connection string
Select one from the options given
Solution explorer updated with dataset
Instead of dataset you can also use object DataSource as data source of rdlc file.
Step4: Adding DataSource to Report
Open rdlc file in the design view, Click on “Show data sources “under the “Data” menu item and you can simply drag and drop fields to the report.
Drag and drop a table from tool box.
Click on ReportsData sources to add data sources to the report
Drag and drop the fields you wanted on the detail section of the table.
Add footer if need.

Place whatever controls you want on the report and drag field to its expression
You have a couple of categories from which you can have data for the expression.
Under global we have:
Under parameter we have all the parameters you have added to the report.
Step5: Adding Parameters to Report
To communicate between the UI and the report, use parameters.
To add parameter use Reports-> report parameters… menu item
          Rdlc file and the dataset are ready and we can show the report in the web page. You can set the page properties using Report properties dialog
        Step6: Adding rdlc on aspx page
Add a new aspx page and drag a report view control on it. Use the smart tag to choose report. Once you add the report,
Report source as well can be configured.
    Step7: Run the web page and you will be able to view the report.

           Step8: How to attach DataSource dynamically from C# to rdlc file

Step9: How initialize parameters from C# to rdlc file
     // parameters are initialized for the report
     ReportParameter Param0 = new ReportParameter("fromDate", fromDate.ToString(dateFormat));
     ReportParameter Param1 = new ReportParameter("toDate", toDate.ToString(dateFormat));
     ReportViewer1.LocalReport.SetParameters(new ReportParameter[] { Param0, Param1 });

Step9:  Deployment Note.

  1. Add the following key to handler section of the web.config file


         <add name="Reserved-ReportViewerWebControl-axd" path="Reserved.ReportViewerWebControl.axd"
         verb="*" type="Microsoft.Reporting.WebForms.HttpHandler,Culture=neutral"  resourceType="Unspecified"/>      

  1. You may get this error “Server Error in '/' Application.
Could not load file or assembly 'Microsoft.ReportViewer.WebForms, Version=' or one of its dependencies. The system cannot find the file specified.”. To solve this mannually copy the following files to the bin folder of your website.

Please make sure you have .NET Framework 3.5 installed on the computer.
When you run ReportViewer.exe, the following files are installed in the Global Assembly Cache folder on the deployment computer.


The error indicates that the system cannot load Microsoft.ReportViewer.Webforms. Please try to manually copy the Microsoft.ReportViewer.WebForms.dll file to the application folder /bin directory. Please refer to the following link for more information about the Report Viewer.

  1. If you are publishing the webstie using framework 3.5 use “Allow this precompiled site to be updatable.

I found the following sites to be very useful while working with RDLC reporting    

Biju Joseph


  1. Thank You Mr Biju its very Useful to New Comers.......... I also Learned lot by this. just have to implement

  2. One more thing can i write more then one SQL Query in single Store Procedure...n call the same SP to Execute different Queries..