Microsoft Visual Studio 2005 ReportViewer Web and Windows Controls New in 2005


Microsoft Visual Studio 2005 ReportViewer Web and Windows Controls New in 2005

Visual Studio 2005 includes the freely distributable ReportViewer Windows and web forms controls.

ReportViewer greatly simplifies embedding of reports in an application.

The ReportViewer Windows control is shown in Figure 27.1.

Figure 27.1. ReportViewer Windows control.

ReportViewer can provide both standalone (local processing mode) and server-based (remote processing mode) rendering.

When ReportViewer is used in local processing mode:

  • ReportViewer renders a report using built-in rendering capabilities of the control and then presents it to a user .

  • SSRS is not used by ReportViewer to process a report in local processing mode.

  • An application provides a client report definition ( .rdlc ) file, which has to be a part of the project and a data set for the control.

Note

Note that report definition file used for local processing has an extension of .rdlc . The extension denotes client RDL files. See http://msdn2.microsoft.com/ms252067.aspx for additional details.


The process to design client reports ( .rdlc files) is different from designing server-based ( .rdl ) reports. .rdlc and .rdl files have a slightly different structure, but can be converted into each other.

Assume that you have already created a Windows or web form project. To display a report in ReportViewer, using the local processing mode, first you need to add a new data set using the following steps:

1.
In Solution Explorer, right-click on the project (not the solution), point to Add, and select New Item. In the Add New Item dialog box, click DataSet. Enter a name for the data set (call it DSEmployeeEmail), and click Add. This adds a new XSD file named DSEmployeeEmail.xsd to the project and opens the DataSet Designer.

2.
In DataSet Designer mode, open the Toolbox, and drag a TableAdapter onto the DataSet design surface. This launches the TableAdapter Configuration Wizard.

3.
On the Choose Your Data Connection page, click New Connection. In the Data Source dialog box, select Microsoft SQL Server. Create connection to AdventureWorks database. Accept the default name AdventureWorksConnectionString. Click Next.

4.
On the Choose the Command Type page, select Use SQL Statements.

5.
On the Enter a SQL Statement page, enter the following T-SQL query (or use Query Builder), and then click Finish:

 SELECT Person.Contact.FirstName, Person.Contact.LastName,  Person.Contact.EmailAddress FROM Person.Contact INNER JOIN HumanResources.Employee  ON Person.Contact.ContactID = HumanResources.Employee.ContactID 

6.
Click the Advanced Options button, deselect all check boxes in the Advanced Options dialog box, accept, and click Next.

7.
On the Choose Methods to Generate page, accept the defaults Fill a DataTable with Method name Fill and Return a DataTable with Method name GetData. Click Next.

8.
On the Wizard Results page, click Finish.

To create a client report that consumes the DSEmployeeEmail data set, complete the following steps:

1.
In Solution Explorer, right-click Reports, point to Add, and click New Item.

2.
In the Add New Item dialog box, click Report. In Name, type EmployeeEmails.rdlc and then click Add to open a graphical design surface. This is the Report Designer component of Visual Studio 2005.

Note

Note how Report Designer's interface for .rdlc reports is different from the one you have used to develop server-based reports for Report Server projects. For .rdlc reports, there is only a layout design interface. Data or Preview tabs are not available. In the case of .rdlc reports, DataSet Designer performs similar functions to the Data tab, and project execution/debugging performs functions of the Preview tab.


3.
Finish designing the report layout, using techniques learned previously in the book. From the Toolbox window, drag and drop a Table report item on the report. In the Data Sources window, expand the DSEmployeeEmail data set and drag FirstName , LastName , and EmailAddress fields to the detail row of the table.

Complete the third and final set of steps to consume the client report in the ReportViewer control:

1.
From the Toolbox window, drag and drop a ReportViewer control to Form1. (It was created automatically as a part of a project; you can rename it as needed.)

2.A.
Click on the ReportViewer control and click on the tag to launch the ReportViewer Task panel. Click Choose Report from the drop-down and select a report that you want to display. Report names are shown in the form <Project Name>.<Report Name>.rdlc .

2.B.
Alternatively, you can set ReportViewer's properties as follows :

  • Set P ProcessingMode to Local

  • Expand LocalReport and set the ReportEmbeddedResource property to the name of the report form <Project Name>.<Report Name>.rdlc .

2.C.
Alternatively, you can programmatically manipulate the ReportViewer control, as in the following code sample:

 //To ensure that report is processed in the local processing mode reportViewer.ProcessingMode = Microsoft.Reporting.WinForms.ProcessingMode.Local; //Setup Report path reportViewer.LocalReport.ReportEmbeddedResource=                 "ReportViewerControlSample_LocalProcessing.EmployeeEmails.rdlc"; //Render report reportViewer.RefreshReport(); 

The ReportViewerControlSample-LocalProcessing project is included as a sample for this book and demonstrates ReportViewer in the local processing mode.

When used in the remote processing mode, ReportViewer performs the following tasks :

  • First leverages SSRS to render a report

  • Then retrieves a rendered report from SSRS and presents it to a user

To display a report in ReportViewer, using the remote processing mode, set ReportViewer's properties as follows:

  • Set ProcessingMode to Remote

  • Set ReportServerUrl to the URL of a Report Server, for example http://localhost/ reportserver

  • Set ReportPath to the path of the report on the server, for example /Part2/RelationalDBReports/Sales Order

Alternatively, you can programmatically set ReportViewer's properties and render a report as needed in your application using the following code snippet:

 //To ensure that report is processed in the remote processing mode reportViewer.ProcessingMode = Microsoft.Reporting.WinForms.ProcessingMode.Remote; //Setup Report Server Url and Report path reportViewer.ServerReport.ReportServerUrl = new Uri(txtReportServerUrl.Text); reportViewer.ServerReport.ReportPath = txtPath.Text; //Render report reportViewer.RefreshReport(); 

The ReportViewerControlSample-RemoteProcessing project is included as a sample for this book and demonstrates ReportViewer in the remote processing mode.



Microsoft SQL Server 2005 Reporting Services
Microsoft SQL Server 2005 Reporting Services
ISBN: 0672327996
EAN: 2147483647
Year: 2004
Pages: 254

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net