on 09-03-2008 4:49 PM
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
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");
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
83 | |
24 | |
12 | |
9 | |
7 | |
6 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.