SAP Knowledge Base Article - Public

1297885 - How to add a parameter using the Crystal Reports .NET inproc RAS SDK


How to add a parameter using the Crystal Reports .NET inproc RAS SDK ?

Reproducing the Issue

  • .NET Visual Studio 2005
  • C#
  • Resolution

    sample code:

               using CrystalDecisions.CrystalReports.Engine;
               using CrystalDecisions.ReportAppServer.ClientDoc;

               ReportDocument                                                                                           m_boReportDocument;
               ISCDReportClientDocument                                                                        m_boReportClientDocument;

               CrystalDecisions.ReportAppServer.DataDefModel.ParameterField     m_boParameterField;
               CrystalDecisions.ReportAppServer.ReportDefModel.Section                m_boSection;
               CrystalDecisions.ReportAppServer.ReportDefModel.FieldObject         m_boFieldObject;

                //create a new ReportDocument
                m_boReportDocument = new ReportDocument();

                //load the RPT file
                //access the ReportClientDocument in the ReportDocument (EROM bridge)
                m_boReportClientDocument = m_boReportDocument.ReportClientDocument;

                //create a parameter field
                m_boParameterField = new CrystalDecisions.ReportAppServer.DataDefModel.ParameterField();

                //set its name
                m_boParameterField.Name = "m_boParameterField";
                //set its type
                m_boParameterField.Type = CrystalDecisions.ReportAppServer.DataDefModel.CrFieldValueTypeEnum.crFieldValueTypeStringField;
                //add it to the report definition

                //this will not prompt as the parameter is not yet in use. We will have to add it to the report first

                //get the section we want to use.  In this case the report header.
                m_boSection = m_boReportClientDocument.ReportDefController.ReportDefinition.ReportHeaderArea.Sections[0];

                //create a new field object.
                m_boFieldObject = new CrystalDecisions.ReportAppServer.ReportDefModel.FieldObject();
                //set where to get the data from (parameter field name)
                m_boFieldObject.DataSourceName = "{?m_boParameterField}";
                //set the type
                m_boFieldObject.FieldValueType = CrystalDecisions.ReportAppServer.DataDefModel.CrFieldValueTypeEnum.crFieldValueTypeStringField;
                //set the location
                m_boFieldObject.Top = 100;
                m_boFieldObject.Left = 3000;
                //set the size
                m_boFieldObject.Height = 240;
                m_boFieldObject.Width = 2115;
                //set the font info
                m_boFieldObject.FontColor = new CrystalDecisions.ReportAppServer.ReportDefModel.FontColor();
                m_boFieldObject.FontColor.Font.Name = "Arial";
                m_boFieldObject.FontColor.Font.Size = 10;
                //set the alignment
                m_boFieldObject.Format.HorizontalAlignment = CrystalDecisions.ReportAppServer.ReportDefModel.CrAlignmentEnum.crAlignmentLeft;
                //add the field to the report header
                m_boReportClientDocument.ReportDefController.ReportObjectController.Add(m_boFieldObject, m_boSection, -1);

                //display in reportviewer
                crystalReportViewer1.ReportSource = m_boReportDocument;


    How add  parameter Crystal Reports .NET inproc RAS SDK , KBA , BI-DEV-NET-SDK , .NET SDK / COM SDK , How To


    Crystal Reports 2008 V1 ; SAP Crystal Reports XI R2 ; SAP Crystal Reports, developer version for Microsoft Visual Studio