Create RDLC Report In C# ASP.NET

RDLC Stands for Report Definition Language Client Side. It is used to create reports using Microsoft Reporting Technology.

It is not a third party report and is a built-in reporting service in Microsoft Visual Studio.

Benefits:

  1. Runs on client side
  2. Run Based on only one Dataset
  3. Run Based on one Data Source
  4. No need to install any Reporting Service Instance

Here are the steps to create a new RDLC Report in C#.

Step 1: To create a new website start Visual Studio 2008, Go to File, then click New Web Site.

Then choose the path where we have to save the website folder and mention the website name as whatever you need. Here, I have given the website name as RDLC.

Create a new website
                                                   Figure 1: Create a new website

Then hit OK button.

Step 2: Now we are going to create a Dataset for our report. Here are the steps:

Right click the website name folder RDLC, Add new Item, then choose Dataset

Dataset Creation
                                                         Figure 2: Dataset Creation

Mention the dataset name and then hit Add button to explore the dataset window.
Now your dataset RDLC placed under the App_Code folder then the following dataset window will open.

Dataset window
                                                      Figure 3: Dataset window

Step 3: In the working area of the dataset window right click , Add, then click DataTable.

Adding Data Table
                                                      Figure 4: Adding Data Table

Now the data table is added into the dataset working area field like the following,

Data Table
            Figure 5: Data Table

After the table creation right click the table, then Add and click Column to add column.

Adding Column
                              Figure 6: Adding Column

Add the data column whatever you need and then change the table name to tblStudent.

After Column Field Added
Figure 7: After Column Field Added

Now your data set is ready to connect with our report.

Step 4: After dataset creation we are going to create RDLC.

Right click website name folder, click Add new item, then choose Report Wizard.

Report Creation
                                                               Figure 8: Report Creation

Mention the report name as Student.rdlc and then hit Add button. After clicking add button the following pop up window will open. In this window hit next button.

Pop up window
                                                      Figure 9: Pop up window

After clicking next button it will take you into the data source selection window.

Data Source selection window
                                          Figure 10: Data Source selection window

In this window select data source that is our tblstudent dataset and then click Next button.

Then choose the report type as Tabular and then hit next. It will take you into the following tab. In this tab choose whatever fields you need to display it into your report. Select the fields in Available fields then hit Page button to add it into the Displayed Fields column. Then choose table layout whatever you want and then hit next then choose the table style. Here I have to choose the table style as forest. After that click Finish button to exit the report creation wizard.

Now your report displayed into the following format.

RDLC Report
                                                         Figure 11: RDLC Report

Step 5: Now we are going to add a reporting viewer into our webpage.

In RDLC report we need to add reporting viewer means we need a Script manager that is Ajaxcontroltoolkit.dll to be added into our webpage reference.

Choose ScriptManager in Ajax Extension Tool box.

Adding Script Manager
                                       Figure 12: Adding Script Manager

Then choose ReportViewer under Reporting toolbox

Adding Report Viewer
                                             Figure 13: Adding Report Viewer

Step 6:
Coding to bind a Report from database.

Adding the following reference into our code page.
  1. using System.Data;  
  2. using System.Data.Sql;  
  3. using System.Data.SqlClient;  
  4. using Microsoft.Reporting.WebForms;  

  5. public partial class_Default: System.Web.UI.Page  
  6. {  
  7.     protected void Page_Load(object sender, EventArgs e)  
  8.     {  
  9.         SqlConnection con = newSqlConnection("Data Source=sql Server name ;Initial Catalog=ResultDB;Integrated Security=True");  
  10.         if (!IsPostBack)  
  11.         {  
  12.             string strQuery = "SELECT * FROM tblStudent";  
  13.             SqlDataAdapter da = newSqlDataAdapter(strQuery, con);  
  14.             DataTable dt = newDataTable();  
  15.             da.Fill(dt);  
  16.             RDLC ds = newRDLC();  
  17.             ds.Tables["tblStudent"].Merge(dt);  
  18.             ReportViewer1.ProcessingMode = ProcessingMode.Local;  
  19.             ReportViewer1.LocalReport.ReportPath = Server.MapPath("Student.rdlc");  
  20.             ReportDataSource datasource = newReportDataSource("RDLC", ds.Tables[0]);  
  21.             ReportViewer1.LocalReport.DataSources.Clear();  
  22.             ReportViewer1.LocalReport.DataSources.Add(datasource);  
  23.         }  
  24.     }  
  25. }  
After execution you can see what the following error means,

Error
                                                         Figure 14: Error

Paste the following code into your web.config file under httphandlers.
  1. <addverb="*"path="Reserved.ReportViewerWebControl.axd"type="Microsoft.Reporting.WebForms.HttpHandler, Microsoft.ReportViewer.WebForms, Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />  

Read more articles on ASP.NET: