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