cancel
Showing results for 
Search instead for 
Did you mean: 

Subsequent SubReports overwriting earlier parameters

Former Member
0 Kudos

For some reason any subreports that I add overwrite the parameters of the earlier subreports that are added.

I have tried renaming the report name, this happens with totally different subreports... the last one is the only

one that the parameters stick. I get prompted to enter all previous parameters from all but the last subreport.

Here is a simple code snippet that just adds a subreport twice and I get prompted for the first

subreport parameters: (I normally am not running the same report more than once with the same values,

this is only for example purposes)


            Try
                Dim intNewSection As Integer = 0
                Dim boReportDocument As ReportDocument
                Dim boReportClientDocument As ISCDReportClientDocument
                Dim boSubreportClientDocument As CrystalDecisions.ReportAppServer.Controllers.SubreportClientDocument
                Dim boArea As CrystalDecisions.ReportAppServer.ReportDefModel.Area
                Dim boSection As CrystalDecisions.ReportAppServer.ReportDefModel.Section
                Dim sarSubRptFile(1) As String
                Dim strSubRptFile As String
                sarSubRptFile(0) = Application.StartupPath & "\Reports\Selected Checklist.rpt"
                sarSubRptFile(1) = Application.StartupPath & "\Reports\Selected Checklist.rpt"

                boReportDocument = New ReportDocument()

                boReportDocument.Load(strReportFilespec)
                boReportClientDocument = New ReportClientDocumentClass()

                boReportDocument.SetDataSource(dsProject) 'Point the crystal report at the System.Data.DataSet
                boReportClientDocument = boReportDocument.ReportClientDocument

                For Each strSubRptFile In sarSubRptFile
                    'Get the detail area from the report
                    boArea = boReportClientDocument.ReportDefController.ReportDefinition.DetailArea

                    'Create the new section object
                    boSection = New CrystalDecisions.ReportAppServer.ReportDefModel.Section

                    'Set the properties for the section
                    boSection.Kind = CrystalDecisions.ReportAppServer.ReportDefModel.CrAreaSectionKindEnum.crAreaSectionKindDetail
                    boSection.Name = "CustomDetailSection" & CStr(intNewSection) 'Give it a unique name
                    intNewSection += 1

                    Dim boTestReportDocument As ReportDocument
                    boTestReportDocument = New ReportDocument()
                    boTestReportDocument.Load(strSubRptFile)
                    Dim intSubRptWidth As Integer = boTestReportDocument.ReportClientDocument.ReportDefController.ReportDefinition.PageHeaderArea.Sections(0).Width
                    boTestReportDocument.Close()
                    boTestReportDocument = Nothing
                    boSection.Width = intSubRptWidth

                    'Add the section to the clientdocument
                    boReportClientDocument.ReportDefController.ReportSectionController.Add(boSection, boArea, -1)

                    'Import the sub report with a unique name
                    boSubreportClientDocument = boReportClientDocument.SubreportController.ImportSubreport( _
                     Chr(intNewSection) & Path.GetFileNameWithoutExtension(strSubRptFile), strSubRptFile, boSection)

                    Try
                        Dim rasDataset As ISCRDataSet
                        rasDataset = DataSetConverter.Convert(dsProject)

                        boSubreportClientDocument.DatabaseController.SetDataSource(rasDataset)
                    Catch exData As Exception
                        MsgBox("Error setting data to " & strSubRptFile & vbLf _
                         & "Error: " & exData.ToString, MsgBoxStyle.Information, "Group Report Error")
                    End Try
                    boReportClientDocument.DataDefController.ParameterFieldController.SetCurrentValue( _
                     boSubreportClientDocument.Name, "lowerid", "1a9b-4628-87b1-3026582e0dd6")
                Next

                CrystalReportViewer1.ReportSource = boReportDocument

                CrystalReportViewer1.Show()
            Catch exTest As Exception
            End Try

Does anyone have any idea what I am doing wrong - why is the subreport parameters getting blown away on all but the last subreport.. This happens even if the parameter names are different.

Thanks,

Jeff

Accepted Solutions (1)

Accepted Solutions (1)

former_member200290
Contributor
0 Kudos

I am getting different behaviour, I have pasted some simplified code below that works for me. It imports the same subreport into the main report twice, and sets the first subreport's paramter to 1234 and the second's to abcd.

Trevor


SubreportClientDocument scd =rptclientdoc.SubreportController.ImportSubreport ("report0","c:\\param.rpt",rptclientdoc.ReportDefController.ReportDefinition.DetailArea.Sections [0]);
   
  rptclientdoc.DataDefController.ParameterFieldController.SetCurrentValue ("report0","test","1234");

  scd =rptclientdoc.SubreportController.ImportSubreport ("report1","c:\\param.rpt",rptclientdoc.ReportDefController.ReportDefinition.DetailArea.Sections [0]);
   
  rptclientdoc.DataDefController.ParameterFieldController.SetCurrentValue ("report1","test","abcd");

Former Member
0 Kudos

Thanks Trevor,

It turns out that if I remark out these lines, the parameters start working. I'm not sure what they have to do with the parameters, but it seams to do the trick... now I need to figure out how to update the DataSource without messing up the parameters.

Here is the code that is messing up the parameters:


      Dim rasDataset As ISCRDataSet
      rasDataset = DataSetConverter.Convert(dsProject)     'dsProject is a .net dataset that is coming into this report
      boSubreportClientDocument.DatabaseController.SetDataSource(rasDataset)

This works fine if I am not using parameters on more than one subreport... but if I use parameters on more than one subreport, only the last ones work and I get prompted for all earlier subreports.

Thanks,

Jeff

Former Member
0 Kudos

It turns out if I have:

boSubreportClientDocument.DatabaseController.SetDataSource(rasDataset)

OR

boReportClientDocument.VerifyDatabase()

AFTER the SubReport has been imported, I get prompted for parameters.

I moved the boReportClientDocument.VerifyDatabase() before importing any subreports

But I am not sure what to change the SetDataSource line to in order to stop this problem.

If I remove both of these from happening after importing the subreport, it works fine,

but I need to have SetDataSource to send the latest data to the subreport... otherwise

it does not see any new data.

How do I do this without it messing up parameters?

Thanks,

Jeff

Former Member
0 Kudos

Trevor,

Any ideas how to get around this bug?

Any time I set the datasource on a subreport with parameters, then the

parameters on all but the last subreport get blown away and it prompts me for the parameters.

If there is some kind of work around, I would greatly appreciate it

Thanks,

Jeff

Former Member
0 Kudos

Trevor

i have tried setSetCurrentValue for subreportclentdocument, it returned error "invalid field name"

do you have any solution for this?

Thanks

Padmanaban V

Answers (1)

Answers (1)

Former Member
0 Kudos

After opening a case with Crystal, it turns out that the order in which I set the datasource was the problem. It must be done in the following order:

1. Build the report and add all the dynamic subreports.

2. After all the subreports are in place, then set the data source on each and set it on individual tables instead of applying the entire dataset.

3. Then finally set the parameters.

Apparently there is a known issue that setting datasources on subreports can blow away previously set parameters. If this is published anywhere, I was not able to find this. So maybe this can help someone else from going through this pain.

Thanks for everyone's help!

Jeff