none
Reportviewer Subreport Error "Data retrieval failed for the subreport"

    Question

  • I have a report with a subreport.

    Both have pre-filtered datasets based on two combo boxes.

    The main report has data returned. (Filtered stored procedure placed in the .xsd file)

    The subreport when opened as a main report has data returned. (Filtered stored procedure placed in the .xsd file)

    But, when I put the subreport on the main report I get the "Data retrieval failed for the subreport" error message.

    I need a great tutorial in VB that shows all of the steps necessary to get this working properly.

    The Data is managed in ObjectDataSource; one for each report.

    I am using the SubreportProcessingEventArgs that includes the Handles Reportviewer1.DataBinding event.  That's where I add the datasources for the subreport.

    Help!  PLEASE!!!

    • Moved by Kee Poppy Thursday, March 17, 2011 2:51 AM (From:Visual Basic Language)
    Tuesday, March 15, 2011 5:19 PM

All replies

  • Check out the samples at http://code.msdn.microsoft.com/reportviewer. There's a "SupplyingData" sample that shows you how to hook up data for the subreport.
    Cephas Lin This posting is provided "AS IS" with no warranties.
    Thursday, March 17, 2011 3:40 PM
    Moderator
  • I did follow the sample  at http://code.msdn.microsoft.com/reportviewer. It's working on my local machine but when I moved to web server I got error  messsage "Data retrieval failed for the subreport" below is my coding

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

            If Not IsPostBack Then
                Dim ReportViewer1 As New ReportViewer

                ReportViewer1.ProcessingMode = ProcessingMode.Local

                Dim report As FileStream = Nothing
                Dim subreport As FileStream = Nothing
                Dim dts As DataSet = Nothing

                'Try
                report = New FileStream(Server.MapPath("a_main.rdlc"), FileMode.Open, FileAccess.Read)
                ReportViewer1.LocalReport.LoadReportDefinition(report)

                subreport = New FileStream(Server.MapPath("rpt_section5.rdlc"), FileMode.Open, FileAccess.Read)
                ReportViewer1.LocalReport.LoadSubreportDefinition("rpt_section5", subreport)

                ReportViewer1.LocalReport.DataSources.Add(New ReportDataSource("dts_main", GetDataSet("p_pdf_main")))

                AddHandler ReportViewer1.LocalReport.SubreportProcessing, AddressOf SubReportProcessingEventHandler
                ReportViewer1.LocalReport.Refresh()

                Dim pdfContent As Byte() = ReportViewer1.LocalReport.Render("PDF", Nothing, Nothing, Nothing, Nothing, Nothing, Nothing)

                'return to pdf
                Response.Buffer = True
                Response.Clear()
                Response.ContentType = "application/pdf"

                Response.AddHeader("content-disposition", "attachment; filename=Questionnaire.pdf")
                Response.BinaryWrite(pdfContent)
                Response.Flush()
                Response.End()

                'Catch ex As Exception
                'Response.Write(ex.ToString)

                'End Try
            End If

        End Sub

        Protected Sub SubReportProcessingEventHandler(sender As Object, e As SubreportProcessingEventArgs)
          
            e.DataSources.Add(New ReportDataSource("dts_section5", GetDataSet("p_pdf_section5")))

        End Sub

        Protected Function GetDataSet(ByVal spName As String) As DataTable

            Dim cnn As New SqlConnection(ConfigurationManager.ConnectionStrings("cnPath").ConnectionString)
            Dim cmd As New SqlCommand
            Dim ds As New DataSet
            Dim da As SqlDataAdapter

            With cmd
                .Connection = cnn
                .CommandType = CommandType.StoredProcedure
                .CommandText = spName
                .Parameters.Add("@question_batch_id", SqlDbType.Int).Value = 4   ' Request.QueryString("batch")
                Select Case "print"  'Request.QueryString("mode").ToString
                    Case "form"
                        .Parameters.Add("@mode", SqlDbType.Char, 1).Value = "F"
                    Case "view"
                        .Parameters.Add("@mode", SqlDbType.Char, 1).Value = "V"
                    Case Else
                        .Parameters.Add("@mode", SqlDbType.Char, 1).Value = DBNull.Value
                End Select

            End With
            Try
                cnn.Open()
                da = New SqlDataAdapter(cmd)
                da.Fill(ds)
                GetDataSet = ds.Tables(0)

            Catch ex As Exception
                Response.Write("ERROR: " & ex.ToString)
                GetDataSet = Nothing

            Finally
                cmd.Dispose()
                cnn.Close()
                cnn.Dispose()

            End Try

        End Function

    I have an other reportviewer working on the web server with vs 2010 framework 4. Please help. Thanks.

     

    Wednesday, January 04, 2012 6:34 PM
  • Just in case someone is developing in Windows forms and they get to this point (having much less hair than when they started ). You may like to note that  if you are developing your reports and you have not added any parameters to the SubReport you may well being experiencing the subreport data retrieval  issue. In my scenario I fixed the issue by using the SubReportProcessingEventHandler (had been doing for some time that previously) AND in addition to that added a single parameter to the report that is being used as the SubReport and filled it with a default value and PRESTO... Data retrieved thank fully!!

    steve

    Wednesday, March 21, 2012 2:31 AM
  • After a lot of struggle, I found how the data gets into the subreport. make sure you add the handler of the SubreportProcessing event AFTER you've added the datasources to the main report. I did it this way and it worked. SubreportProcessing should be having addition of the datasource for the subreport.

    e.DataSources.Add(new ReportDataSource("DataSet2", DS1.ListFCount));

    Hope this helps.

    Wednesday, December 12, 2012 12:29 AM