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.
- Moved by Kee Poppy Thursday, March 17, 2011 2:51 AM (From:Visual Basic Language)
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
report = New FileStream(Server.MapPath("a_main.rdlc"), FileMode.Open, FileAccess.Read)
subreport = New FileStream(Server.MapPath("rpt_section5.rdlc"), FileMode.Open, FileAccess.Read)
ReportViewer1.LocalReport.DataSources.Add(New ReportDataSource("dts_main", GetDataSet("p_pdf_main")))
AddHandler ReportViewer1.LocalReport.SubreportProcessing, AddressOf SubReportProcessingEventHandler
Dim pdfContent As Byte() = ReportViewer1.LocalReport.Render("PDF", Nothing, Nothing, Nothing, Nothing, Nothing, Nothing)
'return to pdf
Response.Buffer = True
Response.ContentType = "application/pdf"
Response.AddHeader("content-disposition", "attachment; filename=Questionnaire.pdf")
'Catch ex As Exception
Protected Sub SubReportProcessingEventHandler(sender As Object, e As SubreportProcessingEventArgs)
e.DataSources.Add(New ReportDataSource("dts_section5", GetDataSet("p_pdf_section5")))
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
.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
.Parameters.Add("@mode", SqlDbType.Char, 1).Value = "F"
.Parameters.Add("@mode", SqlDbType.Char, 1).Value = "V"
.Parameters.Add("@mode", SqlDbType.Char, 1).Value = DBNull.Value
da = New SqlDataAdapter(cmd)
GetDataSet = ds.Tables(0)
Catch ex As Exception
Response.Write("ERROR: " & ex.ToString)
GetDataSet = Nothing
I have an other reportviewer working on the web server with vs 2010 framework 4. Please help. Thanks.
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!!
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.