Link to home
Start Free TrialLog in
Avatar of Adrian Cross
Adrian Cross

asked on

Sub-report won't show up - "The subreport 'subreport1' could not be found at the specific location ..."

Hi, I've got an ASP.NET project which includes a report (main.rdlc). This report has a sub-report (mySubReport.rldc). Both are set as embedded resources in their properties.
The report runs fine but the subreport does not show up. It comes with the message, on the report itself:


The subreport 'subreport1' could not be found at the specific location /Project_Name Reports/mySubReport. Please verify that the subreport has been published and the name is correct.

Also, when I check the outputwindow I can see the following warning:


Warning: An error occurred while executing the subreport 'Subreport1' (Instance: 0): The report definition for report 'mySubReport' has not been specified (rsErrorExecutingSubreport)



  protected void btnReport_Click(object sender, EventArgs e)
        {
            Warning[] warnings;
            string[] streamIds;
            string mimeType = string.Empty;
            string encoding = string.Empty;
            string extension = string.Empty;

           

            var cnn = new SqlConnection(Global.conString);

            ReportViewer viewer = new ReportViewer();
            viewer.ProcessingMode = ProcessingMode.Local;
  
            viewer.LocalReport.ReportPath = "Reports/Main.rdlc";
            viewer.LocalReport.EnableExternalImages = true;

            
            // viewer.LocalReport.SubreportProcessing += new SubreportProcessingEventHandler(addsubreport);

           
 	     // 1st data source	
           SqlCommand cmd = new SqlCommand("StoreProcedure", cnn);
            cmd.CommandType = CommandType.StoredProcedure;
            SqlDataAdapter da = new SqlDataAdapter();
            da.SelectCommand = cmd;
            DataSet ds = new DataSet();

            SqlParameter param = cmd.Parameters.AddWithValue("@Param1", "value1");
            param.SqlDbType = SqlDbType.Int;

            SqlParameter p2 = cmd.Parameters.AddWithValue("@Param2", "value2");

            da.Fill(ds);
            DataTable dt = new DataTable();
            dt = ds.Tables[0];


            // 2nd data source
            SqlCommand cmd2 = new SqlCommand("SELECT * FROM Table1", cnn);
            cmd2.CommandType = CommandType.Text;
            SqlDataAdapter da2 = new SqlDataAdapter();
            da2.SelectCommand = cmd2;
            DataSet ds2 = new DataSet();

            Da2.Fill(ds2);
            DataTable dt2 = new DataTable();
            Dt2 = ds2.Tables[0];



            ReportParameter[] p = new ReportParameter[2];
            p[0] = new ReportParameter("Para,1", "value1", false);
            p[1] = new ReportParameter("Param2", "value2", false);


            ReportDataSource rds = new ReportDataSource("DataSet1", dt);
            viewer.LocalReport.DataSources.Add(rds);
          

            ReportDataSource rdsPapers = new ReportDataSource("ds2", dt2);
            viewer.LocalReport.DataSources.Add(rdsPapers);
            viewer.LocalReport.SetParameters(p);

            viewer.LocalReport.Refresh();


              byte[] bytes = viewer.LocalReport.Render("PDF", null, out mimeType, out encoding, out extension, out streamIds, out warnings);

            Response.Buffer = true;
            Response.Clear();
            Response.ContentType = mimeType;
            Response.AddHeader("content-disposition", "attachment; filename=" + "testReport" + "." + extension);
            Response.BinaryWrite(bytes);
            Response.Flush();
        }

Open in new window


I added this line to the code above but the event is not triggering:


      viewer.LocalReport.SubreportProcessing += new SubreportProcessingEventHandler(addsubreport);

Any ideas on this?
ASKER CERTIFIED SOLUTION
Avatar of Misha
Misha
Flag of Russian Federation image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Adrian Cross
Adrian Cross

ASKER

Yes, I added the event for that handler.
I tried to rebuild but I cannot see any rdl.data file.

I created those reports using Report Builder 3.0. Then, I imported the '.rdl' files into my Visual Studio project and renamed them as '.rdlc'.
I can run the reports separately but when I add the second report as a sub-report it wont display.

Maybe something to do it's set up as an embedded resource?