In ActiveReports for .NET 3.0, you can use a Web Service that returns a dataset as the data source for your reports.
This walkthrough illustrates how to create a Windows client application that uses the dataset Web Service as the data source for an ActiveReport.
This walkthrough builds on the dataset Web Service walkthrough and is split up into the following activities:
- Adding an ActiveReport to a Visual Studio project
- Adding controls to each report to display the data
- Adding a web reference to the project
- Adding the code needed to set the report dataset and data member to the dataset and data member returned by the Web Service
- Viewing the report
To complete the walkthrough, you must have access to the Northwind database.
A copy is located at C:\Program Files\Data Dynamics\ActiveReports for .NET 3.0\Data\NWIND.MDB.
When you have finished this walkthrough, you will have a report that looks similar to the following.
Adding an ActiveReport to a Visual Studio project
To add an ActiveReport to a Visual Studio project
- Open a new project in Visual Studio.
- From the Project menu, select Add New Item.
- Select ActiveReports 3.0 File and rename the file rptProducts.
- Click Open (or Add in Visual Studio 2005).
Adding controls to display the data
To add controls to the reports
- Add the following controls to the Detail section of rptProducts, setting their properties as indicated:
Control DataField Name Text Miscellaneous Location Textbox ProductName txtProductName Product Name Size = 2.9, 0.19 0, 0 Textbox UnitPrice txtUnitPrice Unit Price OutputFormat = Currency 3, 0 - Set the CanShrink property of the Detail section to True.
Adding a web reference to the project
To add a web reference
- From the Project menu, select Add Web Reference.
- Type in the address of the .asmx file for the dataset Web Service you created in the previous walkthrough. You can get the address by running the project from the previous walkthrough and copying the url from the address in the browser. (It will look something like http://localhost:####/DataSetWS/Service.asmx where #### is the port number.)
- Click the Go button, and then click the Add Reference button when the Web Service is recognized.
Adding the code needed to set the report's data source control equal to the dataset returned by DataSetWS
To write the code in Visual Studio 2003
- Double-click the gray area below rptProducts. This creates an event-handling method for rptProducts' ReportStart event.
The following example shows what the code for the method looks like.
'Visual Basic Private Sub rptProducts_ReportStart(ByVal sender As Object, ByVal e As System.EventArgs) _ Handles MyBase.ReportStart Dim rpt As New rptProducts() Dim ws As New localhost.DataSetWS() Dim ds As New DataSet() ds = ws.GetProduct() Me.DataSource = ds Me.DataMember = "Products" End Sub //C# private void rptProducts_ReportStart(object sender, System.EventArgs eArgs) { rptProducts rpt = new rptProducts(); localhost.DataSetWS ws = new localhost.DataSetWS(); DataSet ds = ws.GetProduct(); this.DataSource = ds; this.DataMember = "Products"; }
To write the code in Visual Studio 2005
- Double-click the gray area below rptProducts. This creates an event-handling method for rptProducts' ReportStart event.
The following example shows what the code for the method looks like.
'Visual Basic Private Sub rptProducts_ReportStart(ByVal sender As Object, ByVal e As System.EventArgs) _ Handles MyBase.ReportStart Dim rpt As New rptProducts() Dim ws As New localhost.Service Dim ds As New DataSet() ds = ws.GetProduct() Me.DataSource = ds Me.DataMember = "Products" End Sub //C# private void rptProducts_ReportStart(object sender, System.EventArgs eArgs) { rptProducts rpt = new rptProducts(); localhost.DataSetWS ws = new localhost.Service; DataSet ds = ws.GetProduct(); this.DataSource = ds; this.DataMember = "Products"; }
Viewing the report
To view the report
- Add the ActiveReports viewer control to a Windows Form.
- Add the code needed to set the viewer document equal to the report document. See Using the ActiveReports Windows Form Viewer for help.
You can quickly view your report at design time by clicking the Preview tab at the bottom of the designer. |