Académique Documents
Professionnel Documents
Culture Documents
To view reports deployed to a report server or reports that exist on the local file system, you can use the
WebForms ReportViewer control to render them in a Web application.
To add the ReportViewer Control to a Web application
1. Create a new Microsoft ASP.NET Web Site using either Microsoft Visual C# or Microsoft Visual
Basic.
- Or -
Open an exiting ASP.NET Web Site and add a new Web Form.
2. Locate the ReportViewer control in the Toolbox. If the Toolbox is not visible, you can access it
from the View menu by selecting Toolbox.
3. Drag the ReportViewer control onto the design surface of the Web Form.
The ReportViewer control named reportViewer1 is added to the form.
After the control is added to the form the ReportViewer Tasks smart tag will appear prompting you to
select a report. If the report you wish to view has been deployed to a report server select the <Server
Report> option from the Choose Report drop-down list. Once the <Server Report> option is
selected two additional properties will appear, Report Server Url and Report Path. The Report
Server Url is the address to the report server and the Report Path is the full path to the report you
want to render. If you want to view a report in local mode select either the Design a new report option
to launch the report designer or select a report that is already part of the existing project.
Viewing Reports in Remote Processing Mode
Note:
1. Open the Web Site that the report will be added to.
2. From the Website menu, select Add Existing Item.
3. Browse to the location where the AdventureWorks Report Samples project is installed.
The default location is C:\Program Files\Microsoft SQL Server\100\Samples\Reporting
Services\Report Samples\AdventureWorks Sample Reports. For more information about how to
install the samples, see Considerations for Installing SQL Server Samples and Sample
Databases.
4. Select the Sales Order Detail.rdl file and click the Add button.
The Sales Order Detail.rdl file should now be part of the project.
5. Right-click the Sales Order Detail.rdl file in Solution Explorer and select Rename. Rename the
report to Sales Order Detail.rdlc and press ENTER.
If Solution Explorer is not visible, you can open it from the View menu by selecting Solution
Explorer.
The following code example will create a dataset for the sales order data and then render the Sales
Order Detail report in local mode.
C#
Copy Code
protected void Page_Init(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
// Set the processing mode for the ReportViewer to Local
reportViewer.ProcessingMode = ProcessingMode.Local;
localReport.DataSources.Add(dsSalesOrder);
localReport.DataSources.Add(dsSalesOrderDetail);
SqlCommand command =
new SqlCommand(sqlSalesOrder, connection);
command.Parameters.Add(
new SqlParameter("SalesOrderNumber",
salesOrderNumber));
salesOrderAdapter.Fill(dsSalesOrder, "SalesOrder");
}
SqlCommand command =
new SqlCommand(sqlSalesOrderDetail, connection);
command.Parameters.Add(
new SqlParameter("SalesOrderNumber",
salesOrderNumber));
salesOrderDetailAdapter.Fill(dsSalesOrder,
"SalesOrderDetail");
}
}
Visual Basic
Copy Code
Imports System.Data
Imports System.Data.SqlClient
Imports Microsoft.Reporting.WebForms
localReport.DataSources.Add(dsSalesOrder)
localReport.DataSources.Add(dsSalesOrderDetail)
'Create a report parameter for the sales order number
Dim rpSalesOrderNumber As New ReportParameter()
rpSalesOrderNumber.Name = "SalesOrderNumber"
rpSalesOrderNumber.Values.Add("SO43661")
End If
End Sub
salesOrderAdapter.Fill(dsSalesOrder, "SalesOrder")
End Using
End Sub
salesOrderDetailAdapter.Fill(dsSalesOrder, _
"SalesOrderDetail")
End Using
End Sub
End Class