May 23, 2024
ssrs crystal report

How to Create RDLC Report?

Microsoft Visual Studio offer rdlc reports. With the help of Visual Studio we can easily developed any types of intellectual, analytical reports. This article describes how we can creates rdlc report in c#? Summary of the article:

  • Create a ASP.NET Web Application Project.
  • Adding a Connection String
  • Adding a Data Set
  • Creation of RDLC Report
  • How to Display a RDLC Report?

Create a ASP.NET Web Application Project.
At first we need to Create a ASP.NET Web Application Project.If Microsoft Visual Studio installed, Start it and select New Project from the file menu.In the New Project dialog box:

  • From the Installed Templates pane Select Visual C#
  • Select the template ASP.NET Web Application
  • Set the project name to MyProject
  • Set the disk location to something like C:\TestProject
  • Click OK
New Project

Adding a Connection String
we need to add or create a connection string in Web.config file.Add the following element to the <connectionStrings> element in Web.config file:

 <add name="ConStr" connectionString="Data Source=localhost;Initial Catalog=TestDB;Persist Security Info=True;User ID=sa;Password=sa123"

Adding a Data Set
We need to include a data set or .xsd file.The steps to include a data set:
Right click on Solution Explorer and click Add New Item or from the project menu select Add New Item.

From the Add New Item dialog box click Data template and select DataSet. Set its name MyDataSet.xsd and click Add.

Open the data set MyDataSet.From the Server Explorer, drag the database item (Table, Procedure) on it. We are using a procedure and its name is [TestProcedure].

Data Set

Remember its properties. It has a Data table and table adapter.
DataTable: TestProcedure
TableAdapter:TestProcedureTableAdapter(It has the connection string)

Properties Window

Creation of RDLC Report
We will create a rdlc report using above data set. The steps to create a rdlc report:

Right click on Solution Explorer and click Add New Item or from the project menu select Add New Item.

From the Add New Item dialog box click Reporting template and select Report. Set its name Report1.rdlc and click Add.

Open the report or rdlc file.From the Report Data click New and select Dataset.

Report Data

In the Dataset Properties dialog box chose the Dataset:
Name: DataSet1
Data source: MyDataSet
Available datasets: TestProcedure
Click Ok

Dataset Properties

Right click on the report and select Table. We can insert Page Header, Page Footer, shapes, image to design the report according our requirements. Click on Data and select the column name. We can also add the columns form the Report Data panel. If need, we can add or delete number of column.

Sample RDLC Report

How to Display a RDLC Report?
The steps to display the .rdlc report are given bellow:

Step 1
Select the form or page that will display the report. Add a ScriptManager on the top of the page.

Step 2
From the Toolbox add a ReportViewer control to the Web page or form.Set the Size and position of the control on the page or form.

Step 3
In the Page_Load event write the following C# code. Include the namespace “Microsoft.Reporting.WebForms;”

if (!IsPostBack)
    MyDataSetTableAdapters.TestProcedureTableAdapter ta = new MyDataSetTableAdapters.TestProcedureTableAdapter();
    MyDataSet.TestProcedureDataTable dt = new MyDataSet.TestProcedureDataTable();
    ReportDataSource rds = new ReportDataSource();
    rds.Name = "DataSet1";
    rds.Value = dt;

    ReportViewer1.LocalReport.ReportPath = "Report1.rdlc";

To preview the report build or deploy the application and browse that page or form.

In this way we can create or design a rdlc report.

Rashedul Alam

I am a software engineer/architect, technology enthusiast, technology coach, blogger, travel photographer. I like to share my knowledge and technical stuff with others.

View all posts by Rashedul Alam →

3 thoughts on “How to Create RDLC Report?

Leave a Reply

Your email address will not be published. Required fields are marked *