0
votes

Hello i have a problem using RDLC subreports. I have a very simple setup where i have persons and their residences.

The problem is that the subreport containing the residence for each person is not loaded, because the SubreportProcessing Event is never fired.

I have set up my reportviewer like this:

private void LoadAnniversaryReport()
        {
            DataSet dt = new ResidentSearchServiceClient().GetAnniversaries();
            residenceDataTable = dt.Tables[1];

            ReportDataSource personDataSource = new ReportDataSource("Dataset", dt.Tables[0]);

            this.ReportViewer.LocalReport.ReportPath = "Reports\\Anniversary\\Anniversary.rdlc";
            this.ReportViewer.LocalReport.DataSources.Clear();
            this.ReportViewer.LocalReport.DataSources.Add(personDataSource);
            this.ReportViewer.LocalReport.SubreportProcessing += ResidenceSubreportProcessing;
            this.ReportViewer.Refresh();
            this.ReportViewer.RefreshReport();

            _isReportViewerLoaded = true;
        }

The subreport has a Parameter called "Id". Here's the xml of the subreports parameter definition:

ScreenShotOfParameterConfig

<ReportParameters>
    <ReportParameter Name="Id">
      <DataType>Float</DataType>
      <Nullable>true</Nullable>
      <Prompt>ReportParameter1</Prompt>
    </ReportParameter>
  </ReportParameters>

And the parents subreport and parameter definition

parentsSubreportAndParameterConf

<Subreport Name="PersonResidences">
    <ReportName>PersonResidences</ReportName>
    <Parameters>
        <Parameter Name="Id">
            <Value>=Fields!ENTITYID.Value</Value>
        </Parameter>
    </Parameters>
    <OmitBorderOnPageBreak>true</OmitBorderOnPageBreak>
    <Style>
        <Border>
            <Style>None</Style>
        </Border>
    </Style>
</Subreport>

The "ReportName" is the exact name of the report on the file system without the .rdlc extension. Both reports are in the same subdirectory.

The parent report works fine without the subreport.

I know this question has been asked before, but none of the answers seem to solve my problem.

Any help would be greatly appreciated.

Edit: Followed this tutorial and experienced the exact same problem https://www.c-sharpcorner.com/article/rdlc-subreport-using-c-sharp-and-wpf/

1

1 Answers

1
votes

Ok so i managed to resolve the problem.

The problem was that, using VS2019, some weird things happen to report definitions as you edit them. This resulted in wrong targetnamespaces for me!

Initially when i create a report, the namespace is

xmlns="http://schemas.microsoft.com/sqlserver/reporting/2008/01/reportdefinition"

As soon as you add any parameter to this report, VS will change it to

xmlns="http://schemas.microsoft.com/sqlserver/reporting/2016/01/reportdefinition"

My "Parent" report, did not change (because it does not have any parameters except the on defined in the subreport). But my subreport changed.

Now the default version of the ReportViewer could no longer display the subreport and returned the very informative exception that it couldn't be found.

So i basically did two things:

  • Upgraded my ReportViewer assemblies via Nuget (Microsoft.ReportViewer.VS2015.WinForms)
  • Made sure both reports target the same namespace

I hope this will help somebody someday.