I have created an application in VS 2005 pulling reports created in Crystal Reports XI Release 2. My problem is I have a couple of reports that have linked subreports on them. Does anyone know how to pass a parameter value to a subreport in .NET? I have the following code snippet and it works except that the same data appears in the subreport for all the main reports; unlinking the subreports.

I was originally told that you couldn't pass parameter values to a subreport - to create a parameter on the main report and link to the subreport - which is what I did, but now the reports don't seem to be linked.

Dim lpfdDefinitions As ParameterFieldDefinitions = objReport.DataDefinition.ParameterFields
Dim lpfdDefinition As ParameterFieldDefinition = lpfdDefinitions.Item(lSubreport.ParaName)



mobjReport.SetParameterValue(lSubreport.ParaName, lSubreport.Values.ToArray())
mobjReport.SetParameterValue("PM-@" & lSubreport.ParaName, lSubreport.Values.ToArray(), lSubreport.SubName)

"lSubreport.Values" is loaded higher up in the code by values coming from the main report.
"lSubreport.DataTable" is the datatable that is loaded from the subreport's SQL Query. Any help with this would be greatly appreciated.


For those of you who have the same issue, I have resolved my problem. The following is what I did to get the parameters to pass to the subreport correctly.

Within the subroutine that I get each parameter for each subreport:

For Each lSubreport As SubreportItems In mcolSubreports.Values
      Dim crSubReportDoc As ReportDocument

      crSubReportDoc = mobjReport.OpenSubreport(lSubreport.SubName)

      Dim lpfdDefinitions As ParameterFieldDefinitions = crSubReportDoc.DataDefinition.ParameterFields
      Dim lpfdDefinition As ParameterFieldDefinition = lpfdDefinitions.Item("PM-" & lSubreport.ParaName)

      For Each lRow As DataRow In mobjData.Rows  '// I actually had to move this routine here for it to pass the all the values correctly.
            Dim lpdvValue As ParameterDiscreteValue = New ParameterDiscreteValue

            lpdvValue.Value = lRow("adID").ToString




      mobjReport.SetParameterValue("PM-" & lSubreport.ParaName, lpfdDefinition.CurrentValues.ToArray(), lSubreport.SubName)


This works great and I get the correct record linking the subreport with the main report.

This question has already been answered. Start a new discussion instead.