RDLC Subreport can no show

dfbfdbdfrfrb 1 Reputation point
2022-04-20T09:56:42.92+00:00

I am working with RDLC reports and currently I have a sub report with its properties and parameters within a main report. After trying to generate the report, the below error is shown at the UI :
"Data retrieval failed for the subreport, 'Subreport1', located at: [C:/filepath]"
There is nothing error shown at Visual studio, so I thing the error may not cause by the code.
I think the error comes from the parameters at rdlc not being able to pass into the sub report via the main report . Below is my code:

public ReportViewer Main_Report(string path, ProgressReportFilter item, DataTable dt)
{
                ReportViewer reportViewer = new ReportViewer();
                try
                {

                    var user = UserAccess.GetCurrentUser();
                    reportViewer.ProcessingMode = ProcessingMode.Local;
                    //reportViewer.LocalReport.ReportPath = @"Reports/Main_Report.rdlc";
                    reportViewer.LocalReport.ReportPath = path;
                    reportViewer.SizeToReportContent = true;
                    reportViewer.Width = Unit.Percentage(100);
                    reportViewer.Width = Unit.Percentage(100);
                    reportViewer.LocalReport.SetParameters(new Microsoft.Reporting.WebForms.ReportParameter("Year", item.yyyy));
                    reportViewer.LocalReport.SetParameters(new 
                       Microsoft.Reporting.WebForms.ReportParameter("Month", item.mm));

                    ReportDataSource ds = new ReportDataSource("Main_DataSet", dt);

                    reportViewer.LocalReport.DataSources.Add(ds);

                    reportViewer.LocalReport.SubreportProcessing += new 
                        SubreportProcessingEventHandler(Detail_Alco);
                    reportViewer.LocalReport.Refresh();
                }
                catch (Exception e)
                {}
                return reportViewer;
            }

       void Detail_Alco(object sender, SubreportProcessingEventArgs e)
        {
            Helper.log.Info("para is  " + e.Parameters[0].Values[0]);


            string serial = e.Parameters["serial"].Values[0].ToString();

            //Helper.log.Info("serial is " + serial);

            Dictionary<string, object> parameters = new Dictionary<string, object>();

            parameters.Add("@serial", serial);


            string spName1 = "SP_Report_MRS_Detail_Breakdown_Report_Sub_Alco";
            SUSDB susdb = new SUSDB();

            DataTable dtAlco = ReportHelp.ToDataTable(susdb.DetailBreakdownReport_SubReport_Alco(spName1, parameters));

            ReportDataSource ds = new ReportDataSource("Detail_Breakdown_Alco", dtAlco);

            e.DataSources.Add(ds);
         }

Any help would be appreciated, many thanks

SQL Server Reporting Services
SQL Server Reporting Services
A SQL Server technology that supports the creation, management, and delivery of both traditional, paper-oriented reports and interactive, web-based reports.
3,065 questions
Developer technologies | ASP.NET | Other
Developer technologies | C#
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Isabellaz-1451 3,616 Reputation points
    2022-04-21T07:09:46.203+00:00

    Hi @dfbfdbdfrfrb

    I guess the subreport can not be in local,you can upload it to report server,or put it in your program.
    In Report Builder,the subreport can only select the report on report server.

    194950-image.png
    Best Regards,
    Isabella


    If the answer is the right solution, please click "Accept Answer" and upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.