SAP Knowledge Base Article - Public

1506482 - How to loop through and set subreport parameters using the RAS SDK for VS .NET


  • Incorrectly setting subreport parameters will result in errors or erroneous data
  • Example of a known error:

Unable to cast COM object of type 'System.__ComObject' to class type 'System.String'


Use the following code:

Dim subReportNames As CrystalDecisions.ReportAppServer.DataDefModel.Strings
        subReportNames = mySubreportController.QuerySubreportNames
        Dim srName As String
        For Each srName In subReportNames
            Dim sourceDatabaseForSubreport As CrystalDecisions.ReportAppServer.DataDefModel.Database = mySubreportController.GetSubreportDatabase(srName)
            mySRClientDoc = mySubreportController.GetSubreport(srName)
            Dim subparamfields As Fields = mySRClientDoc.DataDefController.DataDefinition.ParameterFields
            Dim i As Integer
            For i = 0 To subparamfields.Count - 1
                Dim myIscrField As ISCRField = subparamfields(i)
                Dim myParameterField As CrystalDecisions.ReportAppServer.DataDefModel.ParameterField = CType(myIscrField, CrystalDecisions.ReportAppServer.DataDefModel.ParameterField)
                Select Case myParameterField.Name
                    Case "@SurveyNumber"
                        mySRClientDoc.DataDefController.ParameterFieldController.SetCurrentValue(srName, "@SurveyNumber", Int32.Parse(cmbSurveyNum.Text))
                 End Select
            Next subparamfields
        Next srName


Forum thread , KBA , BI-DEV-NET , BI Software Development Kits (SDKs) - .NET or Other , How To


Crystal Reports 2008 V1 ; SAP Crystal Reports XI R2