none
e.DataSources not being updated

    Question

  • I have a report based on business objects.  I created a subreport following the examples on the web.  Here is my code

            void LocalReport_SubreportProcessing(object sender, Microsoft.Reporting.WinForms.SubreportProcessingEventArgs e)
            {
                    DataReportData data = new DataReportData(sessions[sessionCount].ID);
    
                    sessionCount++;
                    Microsoft.Reporting.WinForms.ReportDataSource source = new Microsoft.Reporting.WinForms.ReportDataSource("DataSet1", data.GetData());
    
                    e.DataSources.Add(source);
            }

    So what is happening is that the same data is showing up in each subreport (the first dataset).  But when I step through the code, e.DataSources is being set with the correct dataset.  But for some reason it doesn't show up on the form.  I have verified the e.DataSources is being updated but the subreport is not showing this. 

    Any ideas?

    Friday, April 27, 2012 10:32 PM

Answers

  • Well after many many hours I figured it out and thought I would post it here for people.   If you do not directly use the parameters it evidently doesn't allow you do set the DataSources more then once, so it will use only the first one you set.

    void LocalReport_SubreportProcessing(object sender, Microsoft.Reporting.WinForms.SubreportProcessingEventArgs e)
            {
                int id;
                if (e.Parameters.Count > 0 && int.TryParse(e.Parameters[0].Values[0], out id))
                {
                    ShotDataReportData shotdata = new ShotDataReportData(id);
                    Microsoft.Reporting.WinForms.ReportDataSource source = new Microsoft.Reporting.WinForms.ReportDataSource("DataSet2", shotdata.GetShotData());
                    e.DataSources.Add(source); 
                }  
            }

    • Marked as answer by theMiniTroll Saturday, April 28, 2012 4:15 AM
    Saturday, April 28, 2012 4:15 AM

All replies

  • Well after many many hours I figured it out and thought I would post it here for people.   If you do not directly use the parameters it evidently doesn't allow you do set the DataSources more then once, so it will use only the first one you set.

    void LocalReport_SubreportProcessing(object sender, Microsoft.Reporting.WinForms.SubreportProcessingEventArgs e)
            {
                int id;
                if (e.Parameters.Count > 0 && int.TryParse(e.Parameters[0].Values[0], out id))
                {
                    ShotDataReportData shotdata = new ShotDataReportData(id);
                    Microsoft.Reporting.WinForms.ReportDataSource source = new Microsoft.Reporting.WinForms.ReportDataSource("DataSet2", shotdata.GetShotData());
                    e.DataSources.Add(source); 
                }  
            }

    • Marked as answer by theMiniTroll Saturday, April 28, 2012 4:15 AM
    Saturday, April 28, 2012 4:15 AM
  • Hi theMiniTroll,

    I am experiencing the same issue after upgrading my reports in Visual Studio 2010 to RDLC 2008 format. Before that my reports where working. I am looking for a solution for days now.

    I have an report which contains a subreport within a table.  For each instance of the subreport that is generated the LocalReport.SubreportProcessing event is fired. However for each of these events, it appears that only the first DataTable assigned is used within the report. I can verify that the SubreportProcessing handler is returning the appropriate DataTable for each row, but it appears the first instance of the DataTable is being repeated multiple times.

    I don't understand your provided solution. Can you please give me more explanation? I will realy appreciate it.

    Thanks!

    Michel Miranda

    Tuesday, February 05, 2013 9:02 AM
  • As in my example above, you need to use a parameter, and you need to use it directly in your LocalReport_SubreportProcessing event handler.  Just wrap your handling code like this;
    if (e.Parameters.Count > 0 && int.TryParse(e.Parameters[0].Values[0], out id))

    That will trigger the tables to not use the same data all the time.  Not sure exactly why it is set up this way, but it works for me.  Let me know if it fixes your problem also.
    Tuesday, February 05, 2013 1:45 PM
  • How bizar! After adding a report parameter to the sub report it is working now. Adding the parameter was enough. I am not using or even reading the parameter in my SubreportProcessing event handler.

    Maybe it is an optimization feature of the report viewer.

    Thank you very much for your help! It saved me a lot of time.

    Michel Miranda

    Wednesday, February 06, 2013 5:55 AM