Error: Subreport could not be shown

G

Guest

I have created a report and subreport in VB/ASP.NET. The report works fine
but the subreport will not display. The subreport, when displayed as a
standalone report, works fine.

Any help I can find on this error refers to the WinForms.ReportViewer and
none to the WebForms.ReportViewer.

Anyone have any guidance?
 
S

Steven Cheng[MSFT]

Hi Herb,

From your description, you are using webform reportviewer to display two
SSRS report(client or server report?) in ASP.NET web page. However, the
main report display ok, but the subreport didn't display, correct?

As for the Sub report, have you tried any other very simple report to see
whether it is specific to the sub report's structure or content. Also, when
running the report, what's the error message you get for the subreport when
try displaying it?

Please feel free to let me know if there is anything I missed or if you
have any other finding on this.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead



==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.



Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.

==================================================



This posting is provided "AS IS" with no warranties, and confers no rights.
 
G

Guest

I have 1 .aspx form which contains 1 Webforms.ReportViewer object. The
LocalReport.ReportPath is to my REPORT1.rdlc

REPORT1.rdlc has a subreport with a ReportName of SUBREPORT1

There are no parameters passed between report and subreport.

When I run this, I get the "Subreport could not be shown" error.

If I add a second WebForms.ReportViewer to my .aspx form and link it to
SUBREPORT1.rdlc, it works fine.
 
G

Guest

Additionally, when I link a very simple subreport (text only), it works.

My SUBREPORT1.rdlc refers to a data source and uses a SESSION variable for
it's criteria. Must it use a parameter from the main report?
 
S

Steven Cheng[MSFT]

Hi Herb,

I've performed some local tests and also found the problem when I use a
subreport that bind with some datasources. And after some further research,
I found an existing issue, this is due to the subreport also need to define
its datasource in the main report's page. Actually, both the main report
and subreport will look for datasource/dataset from the hosting aspx
page(where the reportviewer reside). Do you think this is the cause of your
problem. If so , here is a solution to it:

*** Problem Description ***
If you show a report with a subreport in the ReportViewer control and the
ReportViewer control is set to "local", you will get these error messages:

in the VS output window: Warning: An error occurred while executing the
subreport
'subreport1': An error has occurred during report processing.
(rsErrorExecutingSubreport)

in the ReportViewer, we get the message: Error: Subreport could not be shown

<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
<>
*** Resolution ***
In the form that contains the ReportViewer control, you must add an event
handler.
In that event handler, you must manually bind the subreport datasource:
--------------------------------------------------------
Private Sub Local_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the
'AdventureWorksDataSet.Contact' table. You can move, or remove it, as
needed.
Me.ContactTableAdapter.Fill(Me.AdventureWorksDataSet.Contact)

Dim instance As LocalReport = Me.ReportViewer1.LocalReport


AddHandler ReportViewer1.LocalReport.SubreportProcessing, AddressOf
Me.SetSubDataSource

Me.ReportViewer1.RefreshReport()
End Sub

Public Sub SetSubDataSource(ByVal sender As Object, ByVal e As
SubreportProcessingEventArgs)

e.DataSources.Add(New ReportDataSource("AdventureWorksDataSet_Contact",
Me.AdventureWorksDataSet.Contact))


End Sub
--------------------------------------------------------

The table name is derived from the table adapter and the data source name
must be
copied from the report's datasources.
==================================

Hope this helps.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


This posting is provided "AS IS" with no warranties, and confers no rights.
 
G

Guest

I think you will find this example is for the Winforms.ReportViewer, not the
Webforms.ReportViewer. There is no .RefreshReport for the webforms version.
Did you try this in a web application? I was unable to get this to work in a
web application.
 
S

Steven Cheng[MSFT]

Thanks for your reply Herb,

Yes, the original issue record is for a winform reportviewer issue,
however, it also applies to webform scenario. And I did change the code in
my local test page, but forgot to modify it when paste the original code
snippet to you. Here is the test code in my test page:

(you need two datasources on the page, one for your main report and another
for the subreport)
===========================
public partial class test_reportpage : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
ReportViewer1.LocalReport.SubreportProcessing += new
SubreportProcessingEventHandler(SetSubDataSource);
this.ReportViewer1.LocalReport.Refresh();
}

public void SetSubDataSource(object sender,
SubreportProcessingEventArgs e )
{
e.DataSources.Add(new ReportDataSource("DataSet1_rpt_table",
"ObjectDataSource1"));

}
}
=============================

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


This posting is provided "AS IS" with no warranties, and confers no rights.
 
G

Guest

Steven,

My ReportViewer1.LocalReport does not include a SubreportProcessing command.

If you could provide VB examples, I would appreciate it.
 
S

Steven Cheng[MSFT]

Thanks for your reply Herb,

For VB.NET page, you can directly type the
"reportViewer.LocalReport.SubReportProcessing" event regardless of the
intellisense support. Here is the converted VB.NET version of my test
page's codebehind:

=========================
Imports Microsoft.Reporting.WebForms

Partial Class vb_vbreportpage
Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
AddHandler ReportViewer1.LocalReport.SubreportProcessing, AddressOf
SetSubDataSource
ReportViewer1.LocalReport.Refresh()

End Sub


Public Sub SetSubDataSource(ByVal sender As Object, ByVal e As
SubreportProcessingEventArgs)

e.DataSources.Add(New ReportDataSource("DataSet1_rpt_table",
"ObjectDataSource1"))

End Sub

End Class
============================

Hope this helps.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


This posting is provided "AS IS" with no warranties, and confers no rights.
 
G

Guest

Thanks for the reply, sorry I have been away fromthis project for a while and
some of this has slipped my mind. When you refer to:
e.DataSources.Add(New ReportDataSource ("DataSet1_rpt_table",
"ObjectDataSource1"))

what is meant by the ObjectDataSource1? I understand the DataSet1_rpt_table
is the dataset of the subreport. Is the ObjectDataSource1 the view which the
dataset refers to?
 
S

Steven Cheng[MSFT]

Hi Herb,

The "ObjectDataSource1" is the ID of a ObjectDataSource control which
supply the datasource(DataSet) for the report(displayed in ReportViewer).
Actually in Visual Studio 2005 designer, when you choose a client rdlc
report in the ReportViewer, it will automatically generate an
ObjectDataSource control in aspx page for you. However, here since you use
subreport, you need to manually add an ObjectDataSource control that can
supply dataset for your subreport. However, one trick to add such a
ObjectDataSource is add another ReportViewer that display the subreport
individually, and it can automatically help you generate such a DataSource
control. After that you can remove the temp reportViewer and keep the
ObjectDataSource and use it for the first ReportViewer (that use sub
report).

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


This posting is provided "AS IS" with no warranties, and confers no rights.
 
S

Steven Cheng[MSFT]

Hi Herb,

Have you got any progress? Does the further info in my last reply also
helps some?

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


This posting is provided "AS IS" with no warranties, and confers no rights.
 
G

Guest

Steven,
Sorry, I have been having some PC issues. I will test this by Monday and get
back to you.

Thanks,
Herb
 
G

Guest

Steven,
That worked great, thank you!

Next question. I need to add ANOTHER subreport to this report. Is that
possible? Should I close this topic and start a new question?

Thanks
 
G

Guest

Forget I asked. I found that adding a second event handler did the trick.
Thanks a lot for your help.
 
S

Steven Cheng[MSFT]

Thanks for your followup Herb,

Glad that you've got it working.

Have a good day!

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


This posting is provided "AS IS" with no warranties, and confers no rights.
 
C

Chris

Hi Steven or Herb (or anyone),

I followed this discussion carefully - it seems to match my situation
very closely, but I did not get the success that Herb did at the end.

I'm working in Visual Web Developer 2005, using ASP.NET and VB 2005.

I am trying to create a report with a sub-report.

I first got a basic main report going - created a dataset based on
a simple query, and have no problem generating simple reports using
the ReportViewer control and a corresponding ObjectDataSource that
refers to the dataset tableadapter.

Next I created a "static" subreport (just to try walking before
crawling!). It does not depend on any dataset - it just provides
some static text. I include that as a sub-report in my main report
and it works fine.

Next I created a new dataset for the "real" sub-report. It takes a
single parameter - the key field from the "main" dataset. The aim is
that, when coupled with the main report, it will return the related
records in the sub-dataset for each record in the main report/dataset.
I test this sub-report by hard-coding a default value for the
parameter and it works fine as a stand-alone report, displaying the
correct related records from the sub-dataset for the hard-coded
parameter key value.

So... the last step is to put the sub-report into the main report. I
drop a subreport control into the main report's list control just
like I did with the static sub-report, right-click on it to open
the Properties dialog, choose the "real" sub-report (not the static
one this time) in the General tab, and finally set the parameter on
the Parameters tab (parameter name is SiteID, parameter value is
set from the drop-down to =Fields!SiteID.Value). This was my first
attempt and I thought it would be sufficient, but instead of getting
the sub-reports I get the error message:

Error: Subreport could not be shown.

That's when I found your recent discussion, and I tried what seemed to
be the 2 key issues in the solution: (1) adding some code-behind to
set the sub-datasource in the processingevent handler, and (2) adding
an <asp:ObjectDataSource> for the sub-dataset to the aspx page. Having
done both of those, the error remains.

I set a breakpoint in the SetSubDataSource() handler - it never
fires, so I infer that the SubreportProcessing event is not being
raised(?).

I'm sure the devil is in the details, and I can provide those to
you as we go - this message is already too long, so I'll leave it
here for now and hope to hear from one of you soon... Thanks in
advance!

Chris
 
D

denise co

Hi, Steven and everybody here,

Did that work for everyone? I did the same thing advised by Steven and
still have the same problem. Anyone see what the problem is? Thanks. I
used the sql northwind database for testing.

Denise

==========================================
public partial class _Default : System.Web.UI.Page
{

protected void Page_Load(object sender, EventArgs e)
{
this.ReportViewer1.LocalReport.DataSources.Add(new
ReportDataSource("CustomerOrderDataSet_Customers",
CustomerDataSource.ID));
this.ReportViewer1.LocalReport.SubreportProcessing += new
SubreportProcessingEventHandler(this.SetSubDataSource);
this.ReportViewer1.LocalReport.Refresh();
}

public void SetSubDataSource(object sender,
SubreportProcessingEventArgs e)
{
e.DataSources.Add(new
ReportDataSource("CustomerOrderDataSet_Orders", OrderDataSource.ID));

}

}
=============================================
 
Joined
Jan 3, 2008
Messages
2
Reaction score
0
Some tips to work on ReportViewer

Hi all,

Just like what happened to some, encountered problem despite hooking the SubreportProcessing correctly, be it via aspx autoeventwireup or addhandler in page.load.

One observation is that error in displaying subreport probably is due to missing parameters or datasource. When this happens, I believe the SubreportProcessing will not fire anymore given that the underlying subreport is already not working.

The key that has worked for me is to start with one main report with a subreport within, and one sub report with only a string literal. Test that it works.
Continue to add parameters passing on the subreport's parameter collection.
If all thing works fine, then subsequently add a list to the main report to iterate through the records.

Basically, the idea is -> start small, keep baby step and know where did it went wrong. Sounded like a pretty generic tactic eh?

I notice that it worked pretty well that way. Hope this could help those who need this.

Another point to note:
Old datasource created and then removed ARE NOT COMPLETELY REMOVED and hence the report is expected these datasources to be provided. In the case they are left there without removing and then without populating by you, it would then cause error rendering the report, main or sub.
Solution: Open .rdlc file using xml editor under "open with" option in VS2005, or any text editor. Find the section that goes like "<DataSet Name="OldDataSet">.. </DataSet>". Remove the entire section of xml code then it should get rid of them.

Hope this helps too :)
 
Last edited:
Joined
Jan 3, 2008
Messages
2
Reaction score
0
Another point to note:
Old datasource created and then removed ARE NOT COMPLETELY REMOVED and hence the report is expected these datasources to be provided. In the case they are left there without removing and then without populating by you, it would then cause error rendering the report, main or sub.
Solution: Open .rdlc file using xml editor under "open with" option in VS2005, or any text editor. Find the section that goes like "<DataSet Name="OldDataSet">.. </DataSet>". Remove the entire section of xml code then it should get rid of them.

Hope this helps too :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top