ReportViewer SubReport (vs2005)

M

Madison

Hi there,

I'm working on web application using vs2005 using reportviewer control and
rdlc. The report has 2 subreports. I can get the one subreport to working but
been tried for 2 days for second subreport. I got the message say Error:
Subreport could not be shown. if I place the subreport my it's own page, it's
fine. I tried to switch the subreports in the main report, the report display
fine but not the 2 subreports in the same time.

Any ideas. Thanks.
 
A

Allen Chen [MSFT]

Hi,
I'm working on web application using vs2005 using reportviewer control and
rdlc. The report has 2 subreports. I can get the one subreport to working but
been tried for 2 days for second subreport. I got the message say Error:
Subreport could not be shown. if I place the subreport my it's own page, it's
fine. I tried to switch the subreports in the main report, the report display
fine but not the 2 subreports in the same time.

Did you add the DataSource for your subreport? Please try following code to
see if it works. ObjectDataSource2 is the DataSource of your subreport.

protected void Page_Load(object sender, EventArgs e)
{
this.ReportViewer1.LocalReport.SubreportProcessing+=new
SubreportProcessingEventHandler(LocalReport_SubreportProcessing);

}

void LocalReport_SubreportProcessing(object sender,
Microsoft.Reporting.WebForms.SubreportProcessingEventArgs e)
{


// Please set breakpoint here and check e.DataSourceNames
to get the correct name below
e.DataSources.Add(new ReportDataSource("name",
this.ObjectDataSource2));


}



Regards,
Allen Chen
Microsoft Online Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.

Note: MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 2 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. 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/en-us/subscriptions/aa948874.aspx
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
M

Madison

Thank you for your repy.

Here is my codes

<div>
<rsweb:ReportViewer ID="ReportViewer1" runat="server" >
<LocalReport ReportPath="form\grantagreement_main.rdlc">
<DataSources>
<rsweb:ReportDataSource DataSourceId="ObjectDataSource1"
Name="fGrantApplicationTerms_p_forms_grant_agreement_1customer" />
<rsweb:ReportDataSource DataSourceId="ObjectDataSource2"
Name="fGrantApplicationTerms_p_forms_grant_agreement_2projects" />
<rsweb:ReportDataSource DataSourceId="ObjectDataSource3"
Name="fGrantApplicationTerms_p_forms_grant_agreement_3terms" />
</DataSources>
</LocalReport>
</rsweb:ReportViewer>
<asp:ObjectDataSource ID="ObjectDataSource3" runat="server"
SelectMethod="GetData"

TypeName="fGrantApplicationTermsTableAdapters.p_forms_grant_agreement_3termsTableAdapter">
</asp:ObjectDataSource>
<asp:ObjectDataSource ID="ObjectDataSource2" runat="server"
SelectMethod="GetData"

TypeName="fGrantApplicationTermsTableAdapters.p_forms_grant_agreement_2projectsTableAdapter">
</asp:ObjectDataSource>
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
SelectMethod="GetData"

TypeName="fGrantApplicationTermsTableAdapters.p_forms_grant_agreement_1customerTableAdapter">
</asp:ObjectDataSource>

</div>

Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load

AddHandler ReportViewer1.LocalReport.SubreportProcessing, AddressOf
SetSubDataSource
Me.ReportViewer1.LocalReport.Refresh()

End Sub

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

e.DataSources.Add(New
ReportDataSource("fGrantApplicationTerms_p_forms_grant_agreement_2projects",
"ObjectDataSource2"))
e.DataSources.Add(New
ReportDataSource("fGrantApplicationTerms_p_forms_grant_agreement_3terms",
"ObjectDataSource3"))

End Sub

Thanks.
 
M

Madison

Hi Allen;
I set breakpoint at AddHandler
ReportViewer1.LocalReport.SubreportProcessing, AddressOf SetSubDataSource
and debug with step on the debug did not go to SetSubDataSource. Is this the
known issue for ReportViewer with subreport? What is the good way to work
with subreport?

Thanks for your helps.
 
A

Allen Chen [MSFT]

Hi,
I set breakpoint at AddHandler
ReportViewer1.LocalReport.SubreportProcessing, AddressOf SetSubDataSource
and debug with step on the debug did not go to SetSubDataSource. Is this the
known issue for ReportViewer with subreport? What is the good way to work
with subreport?

Thanks for your update. I have written a VB.NET project that demonstrates
how to add sub report. You can download it from:

http://cid-2fa13ebc6cc8e80f.skydrive.live.com/self.aspx/Public/NG^_Case^
_SubReport%5E_RDLC%5E_VS2005.zip

I've made some changes in the strongly typed DataSet code so that you can
directly run the project to see the final result without additional
settings.

Could you please compare my code with yours to see whether there're any
differences? If you find the differences but still cannot work it out
please modify my project to create a repro project. I can then test it on
my side to troubleshoot. You can send project to my email:
(e-mail address removed). Please update here after sending the project in case
I missed that email.


Regards,
Allen Chen
Microsoft Online Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).
 
M

Madison

Thanks for your sample.
I ran your sample and the sub report showing fine. In your sample, I did not
see how you link the MainReport.rdlc to SubReport.rdlc? I try to drop my rdlc
to your sample project, I still did not get to work. How do you make the xsd
to be strongly typed DataSet code then I can sent my rdlc to you.
Thank again for your help.
 
A

Allen Chen [MSFT]

Hi,
Thanks for your sample.
I ran your sample and the sub report showing fine. In your sample, I did not
see how you link the MainReport.rdlc to SubReport.rdlc? I try to drop my rdlc
to your sample project, I still did not get to work.

Thanks for your update. Please double click "MainReport.rdlc" on the
solution explorer window. You'll then see the designer window of
"MainReport.rdlc". On the designer window you can see there's a "SubReport"
that was added by me. If you want to add a new sub report, please try
following steps:

1. Find "Subreport" icon from Toolbox, drag it to the designer window, drop
it on the white region of the report.
2. Right click the subreport (gray region), select "Properties" to open
"Subreport Properties" window. On this window, click "General" tab. You
will see a "Subreport:" settings. All reports will be listed in the
dropdown list below "Subreport:" text. Choose one of the reports what you
want to be the subreport of current report and click ok.
How do you make the xsd to be strongly typed DataSet code then I can sent
my rdlc to you.

I'm using the DataSet template to create the strongly typed DataSet. You
can add it by right clicking the project node on the solution explorer
window and select "Add New Item". Then you can see a "DataSet" template. By
drag&drop a table from server explorer window you can quickly create the
strongly typed DataSet. (Refer to
http://support.microsoft.com/kb/320714/en-us for more details)

Rdlc only contains information that how to render the table so it may not
be the cause of the error you met with. Please add your report in the way I
mentioned above to see if it works.

Regards,
Allen Chen
Microsoft Online Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).
 
A

Allen Chen [MSFT]

Hi,
Thanks for your sample.
I ran your sample and the sub report showing fine. In your sample, I did not
see how you link the MainReport.rdlc to SubReport.rdlc? I try to drop my rdlc
to your sample project, I still did not get to work.

Forgot to mention on thing. Please remenber to add code in
LocalReport_SubreportProcessing method in Default.aspx.vb to add a new
datasource for your report. Please refer to the code in my project to add
it.

Regards,
Allen Chen
Microsoft Online Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).
 
M

Madison

Hi Allen;
I'm following your steps exactly. I still get the Error: Subreport could not
be shown. I could get it worked one time but after I made some changed to
dataset, everything go back to subreport could not be shown again. I deleted
the subreports from main report and add them back I will get the errors. I
almost the end of rope. please help. Thank you for your helps.
 
M

Madison

My VS 2005 is V 8.0.50727.762(SP.050727-7600) and .NET Framework V 2.050727
SP2 Do you think I have the most current update for the reports?
 
A

Allen Chen [MSFT]

Hi;
I'm following your steps exactly. I still get the Error: Subreport could not
be shown. I could get it worked one time but after I made some changed to
dataset, everything go back to subreport could not be shown again. I deleted
the subreports from main report and add them back I will get the errors. I
almost the end of rope. please help. Thank you for your helps.

Thanks for your update. If you can get it worked one time I believe there's
no problem of your environment. Could you tell me what changes you've made
that make it stop working? Please set a breakpoint in
LocalReport_SubreportProcessing method. My guess is, the name probably does
not match e.DataSourceNames, which is a common problem when using
subreport. Could please double check this point? If it still doesn't work
please send me the project.

You can send project to my email: (e-mail address removed). Please update here
after sending the project in case I missed that email.

Regards,
Allen Chen
Microsoft Online Support
 
Joined
Nov 21, 2009
Messages
1
Reaction score
0
Subreports and vb.net

I have been trying to find code examples for getting subreports to work. I keep getting the same error please advise. "Error: Subreport could not be shown" I am not sure what I am doing wrong but sure could use some guidance. Thanks
 
A

Allen Chen [MSFT]

Hi;
I'm following your steps exactly. I still get the Error: Subreport could not
be shown. I could get it worked one time but after I made some changed to
dataset, everything go back to subreport could not be shown again. I deleted
the subreports from main report and add them back I will get the errors. I
almost the end of rope. please help. Thank you for your helps.

Do you have any progress on this issue? If you need further assistance
please feel free to ask. I'll do my best to follow up.

Regards,
Allen Chen
Microsoft Online Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).
 
M

Madison

Hi Allen,
Thank you for your follow up.
I just walked away from project to get more refreshing ideas. I got the
report and 2 subreports working the way I wanted it yesterday. Here are steps
for my report:
1. Created dataset (.xsd) 1 for main, 2 for each subreport.
2. Created main.rdlc set datasourec to main.xsd
3. Created 2 subreport.rdlc set datasourec to each subreport.xsd and set
report-parameter for link.
4. Drag and drop subreport from Report Items to main.rdlc and go to
subreport properties, set subreport to subreport and set parameters
5. Create new page and drop ReportViewer, point to main.rdlc
6. codes from page
<form id="form1" runat="server">
<div>
<rsweb:ReportViewer ID="ReportViewer1" runat="server"
Font-Names="Verdana" Font-Size="8pt"
Height="400px" Width="764px">
<LocalReport ReportPath="form\grantagreement_main.rdlc">
<DataSources>
<rsweb:ReportDataSource DataSourceId="ObjectDataSource1"
Name="Fgrant_main_p_forms_grant_agreement_1customer" />
</DataSources>
</LocalReport>
</rsweb:ReportViewer>
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
SelectMethod="GetData"

TypeName="Fgrant_mainTableAdapters.p_forms_grant_agreement_1customerTableAdapter">
</asp:ObjectDataSource>
</div>
</form>

===================================================
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Handles Me.Load

With ReportViewer1
.Visible = True
.ProcessingMode =
Microsoft.Reporting.WebForms.ProcessingMode.Local
.LocalReport.ReportPath = "form\grantagreement_main.rdlc"
.LocalReport.DataSources.Clear()
End With

'report - Main (customer)
Dim rptDataSourceMain As New
ReportDataSource("Fgrant_main_p_forms_grant_agreement_1customer",
GetDataSet("p_forms_grant_agreement_1customer").Tables(0))
ReportViewer1.LocalReport.DataSources.Add(rptDataSourceMain)

AddHandler ReportViewer1.LocalReport.SubreportProcessing, AddressOf
SetSubDataSource

End Sub

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

'report - Sub1 (project)
e.DataSources.Add(New
ReportDataSource("Fgrant_sub1_p_forms_grant_agreement_2projects",
GetDataSet("p_forms_grant_agreement_2projects").Tables(0)))
'report - Sub2 (terms)
e.DataSources.Add(New
ReportDataSource("Fgrant_sub2_p_forms_grant_agreement_3terms",
GetDataSet("p_forms_grant_agreement_3terms").Tables(0)))

End Sub

Protected Function GetDataSet(ByVal spName As String) As DataSet
Dim cnn As New SqlConnection(cnnPath)
Dim cmd As New SqlCommand
Dim ds As New DataSet
Dim da As SqlDataAdapter

With cmd
.Connection = cnn
.CommandType = CommandType.StoredProcedure
.CommandText = spName
.Parameters.Add("@GrantAppID", SqlDbType.Int).Value = 1190
End With
Try
cnn.Open()
da = New SqlDataAdapter(cmd)
da.Fill(ds)

GetDataSet = ds

Catch ex As Exception
Response.Write("ERROR GetDataSet:" & ex.ToString)
Return ds

End Try

End Function

By doing this way I can ran with different grantappid by changing the
parameter for dataset. I hope that this sample code will help some people who
are struggling with subreport. I wish that Microsoft has more helpful samples
subreport. The reportviewer is the good tool to create pdf document in web
application.
Thank you for your kinds.
 

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

Top