5

I have a web page that displays an RDLC report in a ReportViewer. For each record in the main report there is a subreport.

I need to pass the data from 3 fields from each record in the main report as a parameter to the subreports stored procedure.

the main report works but it just says

Error: Subreport could not be shown

I have all the parameters defined in both reports, and I'm handling the localReport_SubreportProcessing event

C# Code

    protected void Page_Load(object sender, EventArgs e)
{       
    this.ReportViewer1.LocalReport.DataSources.Add(new ReportDataSource("Refs_MainDs", SqlDs_RefsReportsMain));
    this.ReportViewer1.LocalReport.SubreportProcessing += new SubreportProcessingEventHandler(localReport_SubreportProcessing);
}
void localReport_SubreportProcessing(object sender, SubreportProcessingEventArgs e)
{
    e.DataSources.Add(new ReportDataSource("Refs_SubDs", SqlDs_RefsReportsSub));
}

ASP Code

<rsweb:ReportViewer ID="ReportViewer1" runat="server" Height="800px" Width="100%" Font-Names="Verdana" Font-Size="8pt" BorderColor="#666666" 
    BorderStyle="Solid" BorderWidth="1px" AsyncRendering="False" ShowPrintButton="False" >
<LocalReport ReportPath="Reports\EOD_Refs_MainReport.rdlc" >
    <DataSources>
        <rsweb:ReportDataSource DataSourceId="SqlDs_RefsReportsMain" Name="Refs_DataSource" />
        <rsweb:ReportDataSource DataSourceId="SqlDs_RefsReportsSub" Name="Refs_DataSource" />
    </DataSources>
</LocalReport>                             

AND

<asp:SqlDataSource ID="SqlDs_RefsReportsMain" runat="server" ConnectionString="<%$ ConnectionStrings:AlphaConnectionString %>" 
    SelectCommand="rpt_RefsReport_Main" SelectCommandType="StoredProcedure">
<SelectParameters>
    <asp:QueryStringParameter Name="RefsID" QueryStringField="RefsID" Type="String" />
</SelectParameters>

Noelle
  • 772
  • 9
  • 18
  • 44
  • 1
    You've got your parameters in the subreport set up to retrieve their values from the parent report's Fields collection? – Ann L. Oct 10 '12 at 12:46
  • 1
    Also, though I haven't done web reports this way: are the Name properties of the ReportDataSource tags supposed to be the same? – Ann L. Oct 10 '12 at 12:48
  • 3
    Finally, as an experiment, it might be worth seeing whether you can load the subreport on its own. – Ann L. Oct 10 '12 at 12:49
  • 1
    Why not have just one DataSource and filter the data based upon rows in the mail report? Making a seperate datasource for each row seems like inviting trouble. – nunespascal Oct 10 '12 at 12:58
  • Each report shares the same datasource just different datasets. the subreports works fine on its own – Noelle Oct 10 '12 at 13:19

2 Answers2

2

Maybe it will help you:Sub report query based on main report

user829081
  • 164
  • 1
  • 17
2

I needed to change the data set for each report they all still use the same data source and then in code you need to set the parameters for each data set

<rsweb:ReportViewer ID="ReportViewer1" runat="server" AsyncRendering="False" ShowPrintButton="False" >
<LocalReport ReportPath="Reports\Report_MainReport.rdlc" >
    <DataSources>
        <rsweb:ReportDataSource DataSourceId="SqlDs_ReportsMain" Name="EOD_Summary_DataSource" />
        <rsweb:ReportDataSource DataSourceId="SqlDs_ReportsMid" Name="EOD_Summary_DataSource" />
        <rsweb:ReportDataSource DataSourceId="SqlDs_ReportsSusp" Name="EOD_Summary_DataSource" />
        <rsweb:ReportDataSource DataSourceId="SqlDs_ReportsRef" Name="EOD_Summary_DataSource" />
    </DataSources>
</LocalReport>                             

<asp:SqlDataSource ID="SqlDs_ReportsMain" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" 
    SelectCommand="rpt_HighLevel" SelectCommandType="StoredProcedure">
<SelectParameters>
    <asp:QueryStringParameter Name="Key" QueryStringField="Key" Type="String" />
</SelectParameters>

and so on for each Report Data Source

in C#

protected void Page_Load(object sender, EventArgs e)
{       
    this.ReportViewer1.LocalReport.DataSources.Add(new ReportDataSource("MainLevelDs", SqlDs_ReportsMain));
    this.ReportViewer1.LocalReport.SubreportProcessing += new SubreportProcessingEventHandler(localReport_SubreportProcessing);
}
void localReport_SubreportProcessing(object sender, SubreportProcessingEventArgs e)
{
    e.DataSources.Add(new ReportDataSource("MidLevelDs", SqlDs_ReportsMid));
}

Don't know if it's the correct way to do it but it works for me!

HTH

Noelle
  • 772
  • 9
  • 18
  • 44