Microsoft KB Archive/919157

= How to display a report that contains a subreport by using the ReportViewer control in Visual Studio 2005 =

Article ID: 919157

Article Last Modified on 5/31/2006

-

APPLIES TO


 * Microsoft SQL Server 2005 Reporting Services

-





SUMMARY
In Microsoft Visual Studio 2005, you cannot directly display a report that contains a subreport by using the ReportViewer control in your application. When you try to display the report, you may receive the following error message:

Error: Subreport could not be shown

Additionally, you will receive the following warning message in the Visual Studio 2005 Output window:

Warning: An error occurred while executing the subreport ‘subreport1’: An error has occurred during report processing. (rsErrorExecutingSubreport)

This issue occurs when all the following conditions are true:
 * You try to show a report by using the ReportViewer control in your application.
 * The report contains a subreport.
 * The processing mode of the ReportViewer control is set to Local.

However, you can display the report by adding an event handler for the SubreportProcessing event of the ReportViewer control. Then, manually set the data source for the report in the event handler process. This article describes how to display a report that contains a subreport by using the ReportViewer control.



MORE INFORMATION
To use the ReportViewer control to display a report that contains a subreport in Local mode, follow these steps:   Add an event handler for the SubreportProcessing event before you call the RefreshReport method. For example, if you want to display the report when the form is loaded, add the following code to the Load event. In this code example, the event handler for the SubreportProcessing event is SubreportProcessingEventHandler:

Microsoft Visual Basic .NET code Private Sub _Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load '   ' Other code is here. '   Dim instance As LocalReport = Me.ReportViewer1.LocalReport

Me.ContactTableAdapter.Fill(Me.AdventureWorksDataSet.Contact)

AddHandler ReportViewer1.LocalReport.SubreportProcessing, AddressOf Me.SubreportProcessingEventHandler Me.ReportViewer1.RefreshReport '   ' Other code is here. ' End Sub Microsoft Visual C# code private void _Load(object sender, EventArgs e) { /*   Other code is here. */

this.ContactTableAdapter.Fill(this.AdventureWorksDataSet.Contact);

this.reportViewer1.LocalReport.SubreportProcessing += new SubreportProcessingEventHandler(SubreportProcessingEventHandler); this.reportViewer1.RefreshReport; /*   Other code is here. */ } Note   represents the name of the form.   Add the code for the event handler, and then manually set the data source for the report in the event handler process. For example, use the following code example.

Note This code example assumes that you have added a data source to the project and bound the data source to the form. The subreport contains data from the data source. For more information about how to bind the data source to the form, visit the following Microsoft Developer Network (MSDN) Web site:

http://msdn2.microsoft.com/en-us/library/h974h4y2(vs.80).aspx

Visual Basic .NET code Public Sub SubreportProcessingEventHandler(ByVal sender As Object, ByVal e As SubreportProcessingEventArgs)

e.DataSources.Add(New ReportDataSource(&quot;AdventureWorksDataSet_Contact&quot;, Me.AdventureWorksDataSet.Contact))

End Sub Visual C# code void SubreportProcessingEventHandler(object sender, SubreportProcessingEventArgs e) { e.DataSources.Add(new ReportDataSource(&quot;AdventureWorksDataSet_Contact&quot;, this.AdventureWorksDataSet.Contact )); } 

