Click here to Skip to main content
15,892,298 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi all,
I have a problem when I add a subreport to my report the subreport doesn't work.
At the moment I don't need pass parameters (in the future yes but at the moment I will stay happy if work without parameters :) )

By separate works both reports (report and subreport), but when I add subreport this fail.
I have 3 datasource with a lot information, with a list that user choose I must send 1,2,3... or x bills with informations of client and details about that bought.
At the moment I only use 2 datasource and a subreport but the idea when it work is have 2 subreport into main report.
The main report use adapter1, the subreport adapter2.
I send you the code for your review, I am sure that is a stupid error but I took a lot hours and I didn't find it (the visual studio 2008 doesn't give me errors).
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Try
            Dim listaIds As New List(Of Integer)
            If Not Session("listaIdPropietarios") Is Nothing Then
                listaIds = Session("listaIdPropietarios")
            End If

            Dim FInicio, FFinal As Date
            Dim adapter1 As New DataSetProductsTableAdapters.P_ObtenerFacturaSTableAdapter
            Dim adapter2 As New DataSetProductsTableAdapters.P_DetalleFacturaTableAdapter
            Dim adapter3 As New DataSetProductsTableAdapters.P_DetalleIvaFacturaTableAdapter
            AddHandler ReportViewer1.LocalReport.SubreportProcessing, AddressOf SetSubDataSource
            Dim tabla As DataSetProducts.P_ObtenerFacturaSDataTable = adapter1.GetData(Convert.ToInt32(Session("Remesa")))
            '-----------------Cojo todos los clientes seleccionados--------------
            'Ahora hay que hacer un for next de todos los id_clientes seleccionados
            Dim tablaFinal As New DataSetProducts.P_ObtenerFacturaSDataTable
            Dim tablaFinal2 As New DataSetProducts.P_DetalleFacturaDataTable
            Dim tablaFinal3 As New DataSetProducts.P_DetalleIvaFacturaDataTable
            If Not tabla Is Nothing Then
                For Each Etiqueta As DataSetProducts.P_ObtenerFacturaSRow In tabla.Rows
                    If listaIds.Contains(Etiqueta.Id_Cliente) Then
                        tablaFinal.ImportRow(Etiqueta)
                        'Miramos que fechas tiene facturado en en esa remesa ese cliente
                        Dim SaberFechas As DataTable = Recibos.ObtenerDetalleRemesa(Etiqueta.Id_Cliente, Session("Remesa"))
                        FInicio = SaberFechas(0)("FInicio")
                        FFinal = SaberFechas(0)("FechaConfeccion")
                        'Recogemos todos sus pedidos de ese periodo
                        Dim tabla2 As DataSetProducts.P_DetalleFacturaDataTable = adapter2.GetData(Convert.ToInt32(Etiqueta.Id_Cliente), FInicio, FFinal)
                        'Añadimos a una tablafinal2 los pedidos de ese usuario, luego los de otro  y los de otro
                        If Not tabla2 Is Nothing Then
                            For Each Etiqueta2 As DataSetProducts.P_DetalleFacturaRow In tabla2.Rows
                                tablaFinal2.ImportRow(Etiqueta2)
                            Next
                        End If
                        Dim tabla3 As DataSetProducts.P_DetalleIvaFacturaDataTable = adapter3.GetData(Convert.ToInt32(Etiqueta.Id_Cliente), FInicio, FFinal)
                        If Not tabla3 Is Nothing Then
                            For Each Etiqueta3 As DataSetProducts.P_DetalleIvaFacturaRow In tabla3.Rows
                                tablaFinal3.ImportRow(Etiqueta3)
                            Next
                        End If
                    End If
                Next
            End If
            ReportViewer1.LocalReport.ReportPath = Server.MapPath("~/Informes/Factura2.rdlc")

            ReportViewer1.LocalReport.DataSources.Add(New ReportDataSource("DataSetProducts_P_ObtenerFacturaS", tablaFinal))
            ReportViewer1.LocalReport.DataSources.Add(New ReportDataSource("DataSetProducts_P_DetalleFactura", tablaFinal2))
            ReportViewer1.LocalReport.DataSources.Add(New ReportDataSource("DataSetProducts_P_DetalleIvaFactura", tablaFinal3))
            ReportViewer1.LocalReport.Refresh()

            Dim mimeType As String = ""
            Dim Encoding As String = ""
            Dim extension As String = ""
            Dim warnings() As Microsoft.Reporting.WebForms.Warning
            Dim streamids() As String
            Dim bytes As Byte() = ReportViewer1.LocalReport.Render("Pdf", Nothing, mimeType, Encoding, extension, streamids, warnings)
            Response.Clear()
            Response.ContentType = "application/pdf"
            Response.AddHeader("Content-Length", bytes.Length.ToString())

            Response.AddHeader("Content-Disposition", "attachment; filename=" & "FacturaS.pdf")

            Response.BinaryWrite(bytes)
            Response.End()
            Response.Close()
        Catch ex As Exception
        End Try
    End Sub
    Protected Sub SetSubDataSource(ByVal sender As Object, ByVal e As SubreportProcessingEventArgs)
        Try
            Dim o As ObjectDataSource = New ObjectDataSource("DataSetProductsTableAdapters.P_DetalleFacturaTableAdapter", "GetData")
            e.DataSources.Add(New ReportDataSource("DataSetProducts_P_DetalleFactura", o))
        Catch ex As Exception
        End Try

    End Sub


Thanks!!
Posted
Comments
thatraja 5-Apr-11 13:42pm    
Check the crystal reports event log viewer & then let us know

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900