Click here to Skip to main content
15,880,405 members
Articles / Web Development / ASP.NET
Article

The new reporting horizons with Microsoft reporting technology

Rate me:
Please Sign up or sign in to vote.
4.61/5 (35 votes)
9 Aug 20063 min read 84.7K   847   45   21
An article for local report engine incorporate in MS VS 2005
Title:       Microsoft local report engine
Author:      Dimitar Nikolaev Madjarov
Email:       madjarov_d_n@yahoo.com
Environment: Microsoft Visual Studio 2005, Windows 2000, XP, 2003
Keywords:    Report's Engine
Level:       "Intermediate"
Description: An article for local report engine incorporate in MS VS 2005
Section      ASP.NET
SubSection   Reporting

Demo Report

Introduction

In this article I will try to show you the magnificent functionality of the local report engine, which the Microsoft Corporation incorporated in the new version of MS Visual Studio 2005.
Every developer knows very well how important it is to have at one’s disposal a powerful, flexible and user friendly report engine.  It doesn’t matter what type of project
we develop, because in 95% of all possible projects, we will need to implement some kind of report functionality. Knowing this fact, Microsoft incorporated in their new version of the
MS Visual Studio v.2005 this functionality. The local reports are similar to the Microsoft Reporting Services under MS SQL 2005. A few months ago I wrote an article on 
this topic." The new reporting horizons with Microsoft Reporting Services 2005"  The best options of this local report engine are that when you make local reports you may
easily switch to and convert them to "remote" reports and run them as part of the Microsoft Reporting Services engine. Another powerful functionality
of the local reports is the possibility to use many data sources in a handy and flexible way. And last, but not least, all this power is free. You do not need to buy or install
any additional licenses to support many users or applications. Fantastic, right?

Creating an report's dataset


The test/demo table in design mode   The demo dataset in design mode

Our first task is to create a dataset with all tables and relations, which will be the basis for building our report. We may skip this stage and provide directly our dataset to
the report engine, but we need this dataset for our next steps. When we create and design a report, we need to see visually all available tables, their fields and data type
of the tables’ fields. This will make our life as developers easier. For the purpose of the current demo, I will create a simple dataset with only one simple table. 
Please forgive me!

Creating an report

Report in design mode

Our next step and task is to create and design a report. This can be done by going to the project's folder and by right clicking of the mouse choose "Add a new item" and
from the list menu selecting an empty report file for creating a report using Microsoft reporting technology. You have to set the name of this new report and location. In our case
I will give the name "demoReport.rdlc" and location the "Rdl" folder from my demo project root folder. Below, I will show you a few important things in my code. If you keep them I promise you that your life will be easier working with Microsoft reporting technology.

//
//Here is code behind Init event of report viewer 
//Initialize the report options always in "Init" event of 
//Report Viewer .............
//</CODE>
protected void rptViewer_Init(object sender, EventArgs e)
{
    rptViewer.ProcessingMode = ProcessingMode.Local;
    rptViewer.LocalReport.EnableExternalImages = false;
    rptViewer.LocalReport.EnableHyperlinks     = false;
    rptViewer.Visible                          = true;
    rptViewer.ShowBackButton                   = true;
    rptViewer.ShowDocumentMapButton            = true;
    rptViewer.ShowExportControls               = true;
    rptViewer.ShowFindControls                 = true;
    rptViewer.ShowParameterPrompts             = false;
    rptViewer.ShowReportBody                   = true;
    rptViewer.SizeToReportContent              = true;
    rptViewer.ShowToolBar                      = true;
    rptViewer.ShowZoomControl                  = true;
    rptViewer.DocumentMapCollapsed             = true;
}

//
//Here is code behind binding of report
//</CODE>
protected void rptViewer_DataBinding(object sender, EventArgs e)
{
   string fD                         = fromDate.VisibleDate.ToString("dd/MM/yyyy").Trim();
   string tD                         = toDate.VisibleDate.ToString("dd/MM/yyyy").Trim();
   DataTable dt                      = new DataTable();
   dt                                = GetData();
   <CODE>//
   // Please notice that ReportDataSet is combination
   // from name of dataset and table/tables in thie dataset "dsReports_myReport" !!!
   //</CODE>
   string bindDs_name                = "dsReports_myReport";
   string reportName                 = "demoReport.rdlc";
   rptViewer.LocalReport.DisplayName = "Demo Report";
   rptViewer.LocalReport.ReportPath  = "Rdl/" + reportName;
   ReportParameter from_Date         = new ReportParameter();
   ReportParameter to_Date           = new ReportParameter();
   ReportParameter filterFromDate    = new ReportParameter();
   ReportParameter filterToDate      = new ReportParameter();
   from_Date.Name                    = "pFromDate";
   to_Date.Name                      = "pToDate";
   filterFromDate.Name               = "filterFromDate";
   filterToDate.Name                 = "filterToDate";
   from_Date.Values.Add(fD);
   to_Date.Values.Add(tD);
   filterFromDate.Values.Add(fromDate.SelectedDate.ToString());
   filterToDate.Values.Add(toDate.SelectedDate.ToString());
   ReportParameter[] myReportParams  = new ReportParameter[] {from_Date, to_Date, filterFromDate, filterToDate};
   rptViewer.LocalReport.SetParameters(myReportParams);
   if (dt != null)
   {
    rptViewer.LocalReport.DataSources.Clear();
    rptViewer.LocalReport.DataSources.Add(new ReportDataSource(bindDs_name.Trim(), dt));
    dt.Dispose();
   }    
}
//
// Do not forget to include and next name space in using clause
//</CODE>
using Microsoft.Reporting.WebForms;

Conclusion

As final words, I would like to thank you for your patience and I hope that this article will be really useful to you and will give you the right direction
when you try to implement Microsoft reporting technology and compare which approach is better. To use local reports or Microsoft Repoting Services.
Please download the sources from this article, and take a look.

N.B I would like to express my special gratitude to my best colleague Mr. Svilen Donev for his valuable support.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Software Developer (Senior) http://www.uplandsoftware.com/
Canada Canada
Canada, Quebec, Laval,
Currnet position: Senior ASP.NET Developer
Company: Uplandsoftware Inc
Certificates: MCITP, MCP, MCTS

Comments and Discussions

 
GeneralNice work Pin
binomial.theorem15-Sep-09 7:49
binomial.theorem15-Sep-09 7:49 
QuestionProgrammatically assigning datasource Pin
Mukund Pujari15-Mar-07 19:00
Mukund Pujari15-Mar-07 19:00 
QuestionOpen .rdlc designer at runtime Pin
Mukund Pujari13-Mar-07 22:51
Mukund Pujari13-Mar-07 22:51 
AnswerRe: Open .rdlc designer at runtime Pin
Dimitar Madjarov14-Mar-07 3:08
Dimitar Madjarov14-Mar-07 3:08 
QuestionBugs in ReportViewer (WindowsForms) Pin
georani21-Aug-06 6:27
georani21-Aug-06 6:27 
AnswerRe: Bugs in ReportViewer (WindowsForms) Pin
Dimitar Madjarov21-Aug-06 9:09
Dimitar Madjarov21-Aug-06 9:09 
QuestionGreat! But I got security problems Pin
Dietmar Kurok17-Aug-06 5:59
Dietmar Kurok17-Aug-06 5:59 
AnswerRe: Great! But I got security problems Pin
Dimitar Madjarov17-Aug-06 9:09
Dimitar Madjarov17-Aug-06 9:09 
Questionhow to open source or demo ? Pin
ruvy16-Aug-06 21:20
ruvy16-Aug-06 21:20 
AnswerRe: how to open source or demo ? Pin
Dimitar Madjarov16-Aug-06 22:02
Dimitar Madjarov16-Aug-06 22:02 
AnswerThanks for your quick replay Pin
ruvy16-Aug-06 22:39
ruvy16-Aug-06 22:39 
GeneralRe: Thanks for your quick replay Pin
Dimitar Madjarov16-Aug-06 22:58
Dimitar Madjarov16-Aug-06 22:58 
GeneralRe: Thanks for your quick replay Pin
ruvy16-Aug-06 23:19
ruvy16-Aug-06 23:19 
it kind of service that sits on iis

Ruvy
GeneralRe: Thanks for your quick replay Pin
Dimitar Madjarov16-Aug-06 23:27
Dimitar Madjarov16-Aug-06 23:27 
GeneralPDF Format Pin
john98715-Aug-06 5:38
john98715-Aug-06 5:38 
GeneralRe: PDF Format Pin
Alan Zhang15-Aug-06 11:33
Alan Zhang15-Aug-06 11:33 
GeneralRe: PDF Format Pin
john98715-Aug-06 11:58
john98715-Aug-06 11:58 
GeneralPossible limitation of local report Pin
Alan Zhang14-Aug-06 23:33
Alan Zhang14-Aug-06 23:33 
GeneralRe: Possible limitation of local report Pin
Dimitar Madjarov15-Aug-06 0:49
Dimitar Madjarov15-Aug-06 0:49 
GeneralRe: Possible limitation of local report Pin
Foxcoming12-Sep-06 17:17
Foxcoming12-Sep-06 17:17 
GeneralRe: Possible limitation of local report Pin
Dimitar Madjarov12-Sep-06 18:52
Dimitar Madjarov12-Sep-06 18:52 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.