Getting the error “Data retrieval failed for the subreport, 'Subreport1'”

236 Views Asked by At

I am trying to get a subreport working. I am using VS 2017.I am getting an error message like "Data retrieval failed for the subreport, 'Subreport1', located at...." while adding my subreports into main reoorts. Here's my code:

public override int RunReport(ref ReportViewer rvNextgenReport)
    {
        DateTime dt = Convert.ToDateTime(ReportCriteria.DeliveryDate, CultureInfo.InvariantCulture);
        string FormattedDeliveryDate = BasePage.GetUSFormattedDate(dt, this.REPORT_BS_DATE_FORMAT);
        string FormattedShortDeliveryDate = BasePage.GetUSFormattedDate(dt, this.REPORT_SHORT_DATE_FORMAT);
        string GenerationTime = BasePage.GetUSFormattedDate(DateTime.Now, this.REPORT_GEN_DATE_FORMAT);
        string firstRouteId;

        int find = ReportCriteria.RouteId.ToString().IndexOf(',');

        if (find > 0) firstRouteId = ReportCriteria.RouteId.ToString().Substring(0, find);
        else
            firstRouteId = ReportCriteria.RouteId;


        // set the report's parameters
        reportParam = new ReportParameter[] {
                            new ReportParameter("Branch", ReportCriteria.BranchName),
                            new ReportParameter("DeliveryDate", ReportCriteria.DeliveryDate),
                            new ReportParameter("IncludeRouteNotesAfterDI", ReportCriteria.includeRouteNotesAfterDI?"1":"0"),
                            new ReportParameter("FormattedDeliveryDate", FormattedDeliveryDate),
                            new ReportParameter("FormattedShortDeliveryDate", FormattedShortDeliveryDate),

                     };


        rvNextgenReport.LocalReport.ReportPath = "RouteCardNewSub.rdlc";

        rvNextgenReport.LocalReport.SubreportProcessing += new SubreportProcessingEventHandler(LocalReport_SubreportProcessing);
        return runReport(ref rvNextgenReport);
    }

    public void LocalReport_SubreportProcessing(object sender, SubreportProcessingEventArgs e)
    {
        LocalReport lr = (LocalReport)sender;
        e.DataSources.Clear();
        ReportDataSource rds;

        if (e.ReportPath.Contains("sureportsNewSub"))
        {
            string routeId = e.Parameters["RouteId"].Values[0];

            for (int index = 1; index < lr.DataSources.Count; index++)
            {
                DataTable dt = (DataTable)lr.DataSources[index].Value;
                DataView dv = new DataView(dt);
                dv.RowFilter = string.Format("RouteId={0}", routeId);
                rds = new ReportDataSource(string.Format("RouteCardNew_DataTable{0}", index + 1), dv.ToTable());
                e.DataSources.Add(rds);
            }
        }
    }

Please note that I won't get reports path in e. Reportspath in LocalReport_SubreportProcessing and I think that may drive this problem. So someone please explain why this object not getting reportspath information.

0

There are 0 best solutions below