ASP.NET,C#.NET,VB.NET,JQuery,JavaScript,Gridview,SQL Server,Ajax,jQuery Plugins,jQuery UI,SSRS,XML,HTML,jQuery demos,code snippet examples.

Breaking News

  1. Home
  2. ASP.NET
  3. How to Create RDLC 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 asp.net 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
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"
        providerName="System.Data.SqlClient"/>
Adding a Data Set
We need to include a data set or .xsd file.The steps to include a data set:
Step1
Right click on Solution Explorer and click Add New Item or from the project menu select Add New Item.
Step2
From the Add New Item dialog box click Data template and select DataSet. Set its name MyDataSet.xsd and click Add.
Step3
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].
Remember its properties. It has a Data table and table adapter.
DataTable: TestProcedure
TableAdapter:TestProcedureTableAdapter(It has the connection string)
Creation of RDLC Report
We will create a rdlc report using above data set. The steps to create a rdlc report:
Step1
Right click on Solution Explorer and click Add New Item or from the project menu select Add New Item.
Step2
From the Add New Item dialog box click Reporting template and select Report. Set its name Report1.rdlc and click Add.
Step3
Open the report or rdlc file.From the Report Data click New and select Dataset.
Step4
In the Dataset Properties dialog box chose the Dataset:
Name: DataSet1
Data source: MyDataSet
Available datasets: TestProcedure
Click Ok
Step5
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.
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();
    ta.Fill(dt);
    ReportDataSource rds = new ReportDataSource();
    rds.Name = "DataSet1";
    rds.Value = dt;

    ReportViewer1.LocalReport.DataSources.Clear();
    ReportViewer1.LocalReport.ReportPath = "Report1.rdlc";
    ReportViewer1.LocalReport.DataSources.Add(rds);
    ReportViewer1.LocalReport.Refresh();
}
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.

No comments