神刀安全网

Create RDLC Report In C# ASP.NET

RDLC Stands for Report Definition Language Clint-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 whatever you need. Here, I have given the website name as RDLC .

Create RDLC Report In C# ASP.NET

                                                   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

Create RDLC Report In C# ASP.NET

                                                         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.

Create RDLC Report In C# ASP.NET

                                                      Figure 3:Dataset window

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

Create RDLC Report In C# ASP.NET

                                                      Figure 4:Adding Data Table

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

Create RDLC Report In C# ASP.NET

            Figure 5:Data Table

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

Create RDLC Report In C# ASP.NET

                              Figure 6:Adding Column

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

Create RDLC Report In C# ASP.NET

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 .

Create RDLC Report In C# ASP.NET

                                                               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.

Create RDLC Report In C# ASP.NET

                                                      Figure 9:Pop up window

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

Create RDLC Report In C# ASP.NET

                                          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.

Create RDLC Report In C# ASP.NET

                                                         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.

Create RDLC Report In C# ASP.NET

                                       Figure 12:Adding Script Manager

Then choose ReportViewer under Reporting toolbox

Create RDLC Report In C# ASP.NET

                                             Figure 13:Adding Report Viewer

Coding to bind a Report from database.

Adding the following reference into our code page.

using System.Data;   using System.Data.Sql;   using System.Data.SqlClient;   using Microsoft.Reporting.WebForms;    public partial class_Default: System.Web.UI.Page   {       protected void Page_Load(object sender, EventArgs e)       {           SqlConnection con = newSqlConnection("Data Source=sql Server name ;Initial Catalog=ResultDB;Integrated Security=True");           if (!IsPostBack)           {               string strQuery = "SELECT * FROM tblStudent";               SqlDataAdapter da = newSqlDataAdapter(strQuery, con);               DataTable dt = newDataTable();               da.Fill(dt);               RDLC ds = newRDLC();               ds.Tables["tblStudent"].Merge(dt);               ReportViewer1.ProcessingMode = ProcessingMode.Local;               ReportViewer1.LocalReport.ReportPath = Server.MapPath("Student.rdlc");               ReportDataSource datasource = newReportDataSource("RDLC", ds.Tables[0]);               ReportViewer1.LocalReport.DataSources.Clear();               ReportViewer1.LocalReport.DataSources.Add(datasource);           }       }   }   

After execution you can see what the following error means,

Create RDLC Report In C# ASP.NET

                                                         Figure 14:Error

Paste the following code into your web.config file under httphandlers.

<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 :

转载本站任何文章请注明:转载至神刀安全网,谢谢神刀安全网 » Create RDLC Report In C# ASP.NET

分享到:更多 ()

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
分享按钮