none
SSRS Subreport VS2010 data retrieval failed for the subreport

    Question

  • I am new to the subreport part of ssrs. I have setup some code which works well with the standard tables and matrix and tablix controls but have been unable to get the subreport to load. I keep getting the same

    error message "data retrieval failed for the subreport".

    Does anyone have any sample code of a subreport working with visual studio 2010?

    My code looks like this though I have tried a bunch of different scenarios to try to pass the data into the subreport.

    private void LoadReport(string reportName)
      {
        reportViewer1.Clear();
        //http://social.msdn.microsoft.com/Forums/en/vsreportcontrols/thread/b039e765-3cc8-43ec-ae67-14b9656bc981
        reportViewer1.Reset(); 
        // Set Processing Mode
        reportViewer1.ProcessingMode = ProcessingMode.Local;
    
        // Set RDL file
        reportViewer1.LocalReport.ReportPath = reportName+".rdlc";
    
      }
    
      public void LoadReport(IEnumerable products, string reportName, string dataSourceName)
      {
        LoadReport(reportName);
    
        ReportParameter myParam = new ReportParameter("ReportParameter1", st.ToString() + " TO " + et.ToString());
          reportViewer1.LocalReport.SetParameters(new ReportParameter[] { myParam });
    
        reportViewer1.LocalReport.DataSources.Add(
          new ReportDataSource(dataSourceName, products));
    
    
        reportViewer1.LocalReport.DataSources.Add(
          new ReportDataSource(dataSourceName+"Subreport", products));
    
        // Process and render the report
        reportViewer1.RefreshReport();
      }
    

     

    Thursday, November 25, 2010 12:40 AM

Answers

All replies

  • Hi pmtolk,

    In order to load data into a subreport, we need to use the SubreportProcessing event, and in the event, add data source for the subreport.
    I implemented a sample about this, you could download it from:
    http://cid-3c7e963ff6ccd974.office.live.com/self.aspx/.Public/LocalReports.zip

    If you have any more questions, please feel free to ask.

    Thanks,
    Jin Chen


    Jin Chen - MSFT
    • Marked as answer by pmtolk Thursday, November 25, 2010 9:26 PM
    Thursday, November 25, 2010 8:05 AM
    Moderator
  • THANK YOU SO MUCH!!!

     

    I did have this code but I had the event added in the form designer which I added via the GUI event property window thing

    and following your example I moved this line

     reportViewer1.LocalReport.SubreportProcessing += new Microsoft.Reporting.WinForms.SubreportProcessingEventHandler(this.reportViewer1_suberport1);

    From the form.designer.cs to after the refresh report as you did in your example and NOW IT WORKS!!!

    Thank you awesome thanksgiving, whew:)

     

     reportViewer1.RefreshReport();
     reportViewer1.LocalReport.SubreportProcessing += new Microsoft.Reporting.WinForms.SubreportProcessingEventHandler(this.reportViewer1_suberport1);

     

    private
    
     void
    
     reportViewer1_suberport1(object
    
     sender, SubreportProcessingEventArgs e)
      {
       ReportDataSource r=reportViewer1.LocalReport.DataSources[0];
       e.DataSources.Add(r);
    
      }
    

     

    Thursday, November 25, 2010 9:22 PM
  • Hello There, Im having the same problem. Im using SQL Server 2008 with VS 2010. Heres my code. Please help me.

     

       EventReportViewer.Reset()

                EventReportViewer.ProcessingMode = ProcessingMode.Local

                EventReportViewer.LocalReport.ReportPath = Application.StartupPath & "\Reports\EventReport.rdlc"

                EventReportViewer.LocalReport.ReportEmbeddedResource = Application.StartupPath & "\Reports\EventReport.rdlc"

     

                'EventReportViewer.LocalReport.LoadSubreportDefinition("subreport1", "")

                evtParams(0) = New ReportParameter("ReportTitle", title)

                evtParams(1) = New ReportParameter("UserName", username)

                       EventReportViewer.LocalReport.SetParameters(evtParams)

                EventReportViewer.LocalReport.DataSources.Add(New ReportDataSource("CurrentDB_RPT_EventReport", datatbl))

                EventReportViewer.LocalReport.DataSources.Add(New ReportDataSource("AgencyDataSet_proc-GetAgencyData", datatbl))

                EventReportViewer.RefreshReport()

    Thursday, December 09, 2010 10:54 PM