Forum  Private Forums  Private Forums ...  SubReports RDLC
Previous Previous
 
Next Next
New Post 7/28/2009 11:24 AM
  avalor
119 posts
5th Level Poster


SubReports RDLC 

Hi,

   I know this is not the best place for my post but im having a bad time with subreports with rdlc, can someone showme code of working subreports, i get an error in the report viewer SubReport cant be shown and an error in output vs An error has occurred during report processing. (rsErrorExecutingSubreport), docs point that i dont have a data source, i try the report alone and work ok, the problem i see is that the event SubreportProcessingEventHandler isnot fired even when im debugging ,i have the following code

private void vrptCorte_Load(object sender, EventArgs e)
        {
            try
            {               
                //myReportViewer2.Reset();

                string strPath = "";
                this.myReportViewer1.ProcessingMode = Microsoft.Reporting.WebForms.ProcessingMode.Local;
                this.myReportViewer1.LocalReport.ReportPath = VWGContext.Current.Application["strRutaReportes"].ToString().Trim() + "rptCorte.rdlc";

                SQL obj = new SQL();
                if (obj.fncConn() < 0)
                    return;
                if (strSql.Equals("") || strSql.Equals(null))
                {
                    strSql = "SELECT     cat_sucursal.suc_nombre, mov_inventario.inv_clave_id, ISNULL(mov_inventario.inv_cantidad, 0) AS inicial, ISNULL " +
                             "((SELECT     mov_cantidad " +
                                 "FROM         view_entradasinv " +
                                 "WHERE     (mov_clave_id = mov_inventario.inv_clave_id)), 0) AS entradas, ISNULL " +
                             "((SELECT     mov_cantidad " +
                                 "FROM         view_salidasinv " +
                                 "WHERE     (mov_clave_id = mov_inventario.inv_clave_id)), 0) AS salidas, ISNULL(mov_inventario.inv_cantidad, 0) + ISNULL " +
                             "((SELECT     mov_cantidad " +
                                 "FROM         view_entradasinv AS view_entradasinv_1 " +
                                 "WHERE     (mov_clave_id = mov_inventario.inv_clave_id)), 0) - ISNULL " +
                             "((SELECT     mov_cantidad " +
                                 "FROM         view_salidasinv AS view_salidasinv_1 " +
                                 "WHERE     (mov_clave_id = mov_inventario.inv_clave_id)), 0) AS final, cat_producto.pro_nombre, mov_inventario.inv_fecha " +
   "FROM         mov_inventario LEFT OUTER JOIN " +
                         "cat_producto ON mov_inventario.inv_clave_id = cat_producto.pro_id LEFT OUTER JOIN " +
                         "cat_sucursal ON mov_inventario.inv_sucursal_id = cat_sucursal.suc_id";
                }
                dtb = obj.GetData(strSql2);
                obj.Close();
                this.myReportViewer1.LocalReport.SetParameters(new ReportParameter[] { new ReportParameter("fechai", strFecha1), new ReportParameter("fechaf", strFecha2) });                
                ReportDataSource objData1 = new ReportDataSource("rptCorteGlobal_DataTable1", dtb);
                this.myReportViewer1.LocalReport.DataSources.Add(objData1);               
                dtb = null;                               
               
                myReportViewer1.LocalReport.SubreportProcessing +=
                    new SubreportProcessingEventHandler(this.LocalReport_SubreportProcessing);
               
            }
            catch (Exception ex)
            {
                MessageBox.Show("Exception" + ex.Message);
            }
        }
        void LocalReport_SubreportProcessing(object sender, SubreportProcessingEventArgs e)                   
        {
            try
            {
                SQL obj = new SQL();
                if (obj.fncConn() < 0)
                    return;
                dtb = obj.GetData(strSql);
                obj.Close();
                ReportDataSource objData = new ReportDataSource("rptCorte_DataSet1", dtb);
                e.DataSources.Add(objData);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
       
        }

 
New Post 7/28/2009 12:52 PM
  rdhatch
635 posts
1st Level Poster




Re: SubReports RDLC 

Hi avalor -

The problem is that your SubReportProcessing handler is not getting called.  You need to attach to the SubReportProcessing event much later in the call stack.

Here's how to do it.  Simply call my Reporting.RunLocalReport() method below, it does the rest for you.

Hope this helps!

Ryan

 

Imports Gizmox.WebGUI.Forms

Imports Microsoft.Reporting.WebForms

 

Public Class Reporting

 

    'Automatically shares Main Report's DataSet with all Subreports

    Public Class SubReportManager

        Private myDataSet As DataSet

        Private myReportViewer As ReportViewer9Wrapper.ReportViewer9

 

        Public Sub New(ByVal argReportViewer As ReportViewer9Wrapper.ReportViewer9, ByVal argDataSet As DataSet)

            myDataSet = argDataSet

            myReportViewer = argReportViewer

            AddHandler myReportViewer.HostedControlPreRender, AddressOf AspControlEventHandler

        End Sub

 

        Private Sub AspControlEventHandler(ByVal sender As Object, ByVal e As Hosts.AspControlEventArgs)

            AddHandler myReportViewer.LocalReport.SubreportProcessing, AddressOf Me.LocalReport_SubreportProcessing

        End Sub

 

        Private Sub LocalReport_SubreportProcessing(ByVal sender As Object, ByVal e As SubreportProcessingEventArgs)

            'Pass DataSet to the Subreport

            PopulateReportDataSource(myDataSet, e.DataSources, e.DataSourceNames)

 

            'Could we automatically Filter the DataSource by the Parameter?

            'Yes - but let's not get too fancy.  The proper DataSet is already being passed, simply apply the Parameter as a Filter in the Subreport's Report DataSources screen

            '1.) Filter Datasource in ReportViewer - don't believe this is possible

            '2.) Filter DataTable before sending it to ReportViewer - yes:  DataTable.DefaultView (add Filter) then DataView.ToTable.

        End Sub

 

    End Class

 

    Public Shared Sub PopulateReportDataSource(ByVal myDataSet As DataSet, ByVal myReportDataSources As ReportDataSourceCollection, ByVal argSpecificTableNames As IList(Of String))

        For Each mySpecificTableName As String In argSpecificTableNames

            PopulateReportDataSource(myDataSet, myReportDataSources, mySpecificTableName)

        Next

    End Sub

 

    Public Shared Sub PopulateReportDataSource(ByVal myDataSet As DataSet, ByVal myReportDataSources As ReportDataSourceCollection, Optional ByVal argSpecificTableName As String = Nothing)

        'Load DataTables from DataSet

        For Each myDataTable As DataTable In myDataSet.Tables

            Dim myReportSource As New ReportDataSource(myDataSet.DataSetName & "_" & myDataTable.TableName, myDataTable)

            'All Tables or Specific Table?

            If argSpecificTableName Is Nothing OrElse argSpecificTableName = myReportSource.Name Then

                myReportDataSources.Add(myReportSource)

            End If

        Next

    End Sub

 

    Public Shared Sub RunLocalReport(ByVal myReportViewer As ReportViewer9Wrapper.ReportViewer9, ByVal myReportPath As String, ByVal myDataSet As DataSet, Optional ByVal myParameters As List(Of ReportParameter) = Nothing)

        myReportViewer.ResetHostedViewer()

        myReportViewer.ProcessingMode = Microsoft.Reporting.WebForms.ProcessingMode.Local

        myReportViewer.LocalReport.ReportPath = myReportPath

        myReportViewer.LocalReport.DataSources.Clear()

 

        'Load DataSet into ReportViewer

        PopulateReportDataSource(myDataSet, myReportViewer.LocalReport.DataSources)

 

        'Pass Parameters

        If myParameters IsNot Nothing Then myReportViewer.LocalReport.SetParameters(myParameters)

 

        'Subreport Manager

        Dim mySubreportManager As New SubReportManager(myReportViewer, myDataSet)

 

        myReportViewer.LocalReport.Refresh()

        myReportViewer.Update()

    End Sub

 

End Class
 

Ryan D. Hatch, VWG MVP
GeniusCode.net | VWG Community Frameworks | VWG Wiki
 
New Post 7/28/2009 2:59 PM
  avalor
119 posts
5th Level Poster


Re: SubReports RDLC 

Hi i try to put the event handler in the last line of the form load and add the extralines  

myReportViewer1.LocalReport.Refresh();
myReportViewer1.Update();               

but it did not work, you said that i that my SubReportProcessing handler is not getting called. but why , the handler is self called when the report is processing, am i missing something? the main report works ok, please help!

 private void vrptCorte_Load(object sender, EventArgs e)
        {
            try
            {                               
                string strPath = "";
                this.myReportViewer1.ProcessingMode = Microsoft.Reporting.WebForms.ProcessingMode.Local;
                this.myReportViewer1.LocalReport.ReportPath = VWGContext.Current.Application["strRutaReportes"].ToString().Trim() + "rptCorte.rdlc";               

                SQL obj = new SQL();
                if (obj.fncConn() < 0)
                    return;               
                dtb = obj.GetData(strSql);
                obj.Close();
                this.myReportViewer1.LocalReport.SetParameters(new ReportParameter[] { new ReportParameter("fechai", strFecha1), new ReportParameter("fechaf", strFecha2) });                
                ReportDataSource objData = new ReportDataSource("rptCorteGlobal_DataTable1", dtb);
                this.myReportViewer1.LocalReport.DataSources.Add(objData);               
                dtb = null;
                myReportViewer1.LocalReport.SubreportProcessing +=new SubreportProcessingEventHandler(this.LocalReport_SubreportProcessing);
                myReportViewer1.LocalReport.Refresh();
                myReportViewer1.Update();               
               
            }
            catch (Exception ex)
            {
                MessageBox.Show("Exception" + ex.Message);
            }
        }       
        void LocalReport_SubreportProcessing(object sender, SubreportProcessingEventArgs e)
        {
            try
            {
                SQL obj = new SQL();
                if (obj.fncConn() < 0)
                    return;
                dtb = obj.GetData(strSql2);
                obj.Close();
                ReportDataSource objData = new ReportDataSource("rptCorte_DataSet1", dtb);
                e.DataSources.Add(objData);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
       
        }

 
New Post 7/28/2009 3:32 PM
  rdhatch
635 posts
1st Level Poster




Re: SubReports RDLC 
Modified By rdhatch  on 7/28/2009 6:36:10 PM)

Using ReportViewer9, You must attach to the SubreportProcessing() event later in the callstack.  I've done the hard work & research to know this.  Just take my word for it.  I've been using extensive Subreports successfully for months.

You may want to have Ori/Palli create a new issue.  Unless you are able to pull Palli off his current workload - this is the workaround.

If you're using ReportViewer9, and perhaps even v8 - Use my code I supplied above.

Ryan


Ryan D. Hatch, VWG MVP
GeniusCode.net | VWG Community Frameworks | VWG Wiki
 
New Post 7/28/2009 4:08 PM
  palli
16578 posts
1st Level Poster




Re: SubReports RDLC 

Hi avalor,

I suggest you try using Ryans code and let us know if that does not work for you. We know Ryan has really put his mind into this and his solution is working.

And Ryan, as always, thanks for your excellent support here !

Palli

 


Páll Björnsson - Visual WebGui support team - Email: support@visualwebgui.com

Please include VWG version information with your questions (best: Full name of VWG installation .MSI file)
To send sample code or other files to support, first zip the relevant project or files,
then rename .ZIP file to different extension like .XIP and finally email as attachment to email address above.
Remember to include full Http Url to the forum thread in the message.
 
Previous Previous
 
Next Next
  Forum  Private Forums  Private Forums ...  SubReports RDLC