SSRS Subreport VS2010 data retrieval failed for the subreport

reporting-servicesssrs-2008

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

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

error message "data retrieval failed for the subreport".

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();
    }

Best Answer

From Jin Chen Microsoft, ModeratorUsers Medals the answer on the msdn forum http://social.msdn.microsoft.com/Forums/en-US/sqlreportingservices/thread/5d2aed0b-ea69-4cbb-b3c4-b306a48fbc30

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);

    }

Related Topic