Databases Reference
In-Depth Information
ReportViewer controls can be used with any data source. That includes relational, nonrelational, and non-
database data sources.
Two different report execution scenarios are supported in both types of the ReportViewer control. The
first is where standard, Report Server reports are deployed and executed on the report server and then
viewed in the control as you would expect. The other is using the ReportViewer control as a mini-
report-hosting engine that allows reports to execute in your application without needing a connection to
the report server. This requires a version of the report definition file that's been retrofitted for client-side
execution. The file is an RDLC file, with C standing for c lient-side processing.
Both RDL and RDLC formats have the same XML schema, but RDLC files allow some elements to contain
empty values. RDLC files also contain information that the ReportViewer control uses to generate data-
binding code. Once you've constructed an RDLC file in the Visual Studio Report Designer, you can then
use the SQL Server Report Designer to add values for the empty elements. Simply change the file exten-
sion from rdlc to rdl , and add the missing values. Typically, the query text will need to be supplied.
Embedding a Server-Side Report in a Windows
Application
In the following exercise, I'll take you through the steps to view a server-side report in a Windows forms
application using the ReportViewer control. The properties and methods of the Web form version of
the control are nearly identical, making your code transportable between Windows and Web application
projects. In the first pass through the example project, I'll be demonstrating Visual Basic .NET code. At
the end of the section, I'll show you code in C# that works the same way but sets the property values
programmatically.
As you know, the report rendering interface can generate a number of toolbar options and parameter
prompts. You may either use these default UI elements or replace them with your own. In the latter case,
it would make sense to hide the default prompts. In the example, I will hide the parameter bar and feed
parameters to the ReportViewer using controls on my form.
I've created a report called Product Sales Detail drill-down that contains two Date type parameters used
to define a range of sales order dates for filtering. These parameters are named OrderDateFrom and
OrderDateTo . The details of the report definition are unimportant for this demonstration.
First, I'll add a form to my Visual Studio 2005 Windows Application project. Although the Report Server
is a component of SQL Server 2005, the ReportViewer control is not. The ReportViewer control is only
included in Visual Studio 2005. Because of that, the ReportViewer must be added to the Control
Toolbox in Visual Studio 2005. With the form in design view, right-click the Toolbox and select Choose
Items... from the context menu. The Choose Toolbox Items dialog is shown in Figure 12-14. Check the
ReportViewer control with the namespace Microsoft.Reporting.WinForms. Note that the ReportViewer
web forms control is also displayed in this dialog.
Depending on your needs, it may be necessary to instantiate classes in your code from the ReportViewer
namespace. To add a reference for this namespace to your project, right-click the project name in the
Solution Explorer and select Add Reference.... The Add Reference dialog is shown in Figure 12-15. The
items listed are similar to those shown previously in Figure 12-14. Highlight the component named
Microsoft.ReportViewer.WinForms, and then click the OK button.
Search WWH ::




Custom Search