aspdotnet-suresh offers articles and tutorials,csharp dot net, articles and tutorials,VB.NET Articles,Gridview articles,code examples of 2.0 /3.5,AJAX,SQL Server Articles,examples of .net technologies

Create RDLC Report in MVC 3 using Dataset with Example in C# in Visual Studio 2010

Dec 15, 2014

Here I will explain how to create and use RDLC report in MVC 3 using dataset with example in c# in visual studio 2010. Normally we use the RDLC report in web forms application. Similar way we can use the RDLC report in MVC also. This post will show you how to use RDLC report in MVC 3 applications.


In previous articles I explained how to create rdlc report in, pass parameters to rdlc report with example in and many more articles related to rdlc reports, Now I will explain how to create RDLC reports in MVC 3 using dataset with example in c# in visual studio 2010.

What is RDLC?

Full meaning of RDLC is Report Definition Language Client-side. It is the extension of report file. It is used to create report s using Microsoft reporting technology. These files are created by the Visual Studio 2005 version of Report Designer. RDLC reports can be executed directly by the Report Viewer control in client side

Please follow the steps given below to create RDLC Report

Before start implementation first design new table in your database and give name EmployeeMaster

Column Name
Data Type
Int(set identity property=true)

After completion of table creation enters some dummy data because we need to use that data to populate reports.

Create a MVC 3 application

Now add new controller for that right click on controller folder and select Add Controller and give name as Employee like as shown below

Once we add controller next step is we need to add view for that right clicks on action result like as shown below

Now open the view page (cshtml), in which we are displaying the report. In the example I am adding report in ManageEmployees/Index. So I have opened Views\ManageEmployees \Index.cshtml

Now add an iframe in Index.html page like as shown below

<iframe id="myReport" width="100%" height="450px" src="../../Report/ReportDataViewer.aspx?ReportID=EmpListReport">
Now the complete code of index.cshtml looks like this

Now we need to create a model for employee and a model service class to retrieve employee information from database.

Create a class EmployeeMaster in Model folder

Our EmployeeMaster class should contain code like as shown below

namespace MVChero.Models
    public class EmployeeMaster
        public int EmpId { get; set; }
        public string EmpName { get; set; }
        public string DesignationName { get; set; }
        public string Location { get; set; }
        public Boolean EmpStatus { get; set; }
Now create a class EmployeeModelService in Model folder

Our EmployeeModelService class should contain code like as shown below

namespace MVChero.Models
public class EmployeeModelService
public List<EmployeeMaster> GetEmployeeInfo(StringBuilder sb)
List<EmployeeMaster> objEmpList = new List<EmployeeMaster>();
using (SqlCommand scmd = new SqlCommand())
scmd.Connection = scon;
scmd.CommandType = CommandType.Text;
scmd.CommandText = "select EMP_ID,EMP_Name,Desg_Name,Location_Name from Emp_Master inner join Designation_Master on Emp_Master.Desg_ID = Designation_Master.DESG_ID " +
"inner join Location_Master on Emp_Master.Location_ID = Location_Master.Location_ID  where Emp_Status = '1'" + sb;
SqlDataReader sdr = scmd.ExecuteReader();
while (sdr.Read())
EmployeeMaster objEmployeeInfo = new EmployeeMaster();
objEmployeeInfo.EmpId = Convert.ToInt32(sdr["EMP_ID"]);
objEmployeeInfo.EmpName = sdr["EMP_Name"].ToString();
objEmployeeInfo.EmpStatus = true;
objEmployeeInfo.DesignationName = sdr["Desg_Name"].ToString();
objEmployeeInfo.Location = sdr["Location_Name"].ToString();
return objEmpList;
Create a folder “Reports” (or any name) in application root folder. Now let’s create our RDLC report. I assume that you are already aware about creating and using RDLC reports otherwise check this link Create RDLC report in with example. Now Right click on “Reports” folder and add new Report as shown below.

Now Add Report Dataset (select EmployeeMaster table from your database)

Now select data source as Model folder and choose GetEmployeeInfo from available datasets, which is added earlier in the EmployeeModelService class. Then it will show fields in right hand side.

Now design the report, and our RDLC report will look like, as shown below

Now add new form “ReportViewer.aspx” in Reports folder. It is required in view page (index.cshtml) for displaying report.

Add report viewer control and a script manager in ReportViewer.aspx page as shown below

Now let’s add the code to set datasource for the report. Write the following code in PageLoad event of ReportViewer.aspx.cs file as shown below

public partial class ReportDataViewer : System.Web.UI.Page
EmployeeModelService objEmpModelService = new EmployeeModelService();
protected void Page_Load(object sender, EventArgs e)
if (!IsPostBack)
if (Request.QueryString["ReportID"] != null)
string reportID = Request.QueryString["ReportID"].ToString();
switch (reportID)
case "EmpListReport":
StringBuilder sb = new StringBuilder("");
DataTable dt = ConvertListToDataTable(objEmpModelService.GetEmployeeInfo(sb));
rvDataViewer.LocalReport.ReportPath = "Report/DataReport.rdlc";
rvDataViewer.LocalReport.DataSources.Add(new ReportDataSource("EmpDataSet", dt));
catch (Exception ex)
static DataTable ConvertListToDataTable(List<EmployeeMaster> empList)
// New table.
DataTable table = new DataTable();
for (int i = 0; i < empList.Count; i++)
table.Rows.Add(empList[i].EmpId, empList[i].EmpName, empList[i].DesignationName, empList[i].Location, empList[i].EmpStatus);
return table;
Now run the application then you can see the report as shown below. I have attached the full source code with it.


Create RDLC Report in MVC 3 using Dataset with Example in C# in Visual Studio 2010
Download Attached Sample

If you enjoyed this post, please support the blog below. It's FREE!

Get the latest,, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email.

subscribe by rss Subscribe by RSS subscribe by email Subscribe by Email


Pradeep said...

thank u sir posting this articlefor rdlc

Unknown said...

Nice Post.Keep Updating sir.

Unknown said...

Please tell me the difference between RDLC Report and Crystal Report. When we should use RDLC Report.

postal inspectors said...

how to pass the run time parameter if we need for where condition in sql query of EmployeModelSevice class

Anonymous said...

Excelente artículo.
Comprobado en Visual Studio 2015 Community.

Unknown said...

But sir how to call myReport Iframe that code not seen in this post,or how to call page from mvc application

Give your Valuable Comments

Note: Only a member of this blog may post a comment.

© 2015 All Rights Reserved.
The content is copyrighted to Suresh Dasari and may not be reproduced on other websites without permission from the owner.