SAP Knowledge Base Article - Public

1300982 - How to create a new report using the Crystal Reports .NET inproc RAS SDK

Symptom

How to create a new report using the Crystal Reports .NET inproc RAS SDK ?

Reproducing the Issue

  • Crystal Reports XI Release 2 Service Pack 2 and higher
  • C#
  • Resolution

    sample code:

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

                //CR Declarations
                ReportDocument                            m_boReportDocument;
                ISCDReportClientDocument        m_boReportClientDocument;
             
                PropertyBag                                                                               m_boLogonInfo;                 // logon info
                PropertyBag                                                                               m_boAttributes;                  // logon attributes
                ConnectionInfo                                                                           m_boConnectionInfo;         // connection info
                CrystalDecisions.ReportAppServer.DataDefModel.Table   m_boTable;                         // table
          
                int iField;
                Field m_boFieldCustomer;                                   // customer field
                Field m_boFieldLastYSale;                                  // last year's sale
                Field m_boFieldCity;                                             // city field
                Field m_boFieldRegion;                                       // region field
                Field m_boFieldCountry;                                      // country 


                //*****************************
                // create a report from scratch
                //*****************************
               
                //Create a new ReportDocument
                m_boReportDocument = new ReportDocument();

                //Access the ReportClientDocument in the ReportDocument (EROM bridge)
                m_boReportClientDocument = m_boReportDocument.ReportClientDocument;
               
                //create new report document
                m_boReportClientDocument.New();
                
                //create logon property
                m_boLogonInfo = new PropertyBag();

                //ODBC
                //create logon attributes
                m_boAttributes = new PropertyBag();
                m_boAttributes["Database DLL"] = "crdb_odbc.dll";
                m_boAttributes["QE_DatabaseType"] = "ODBC (RDO)";
                m_boAttributes["QE_ServerDescription"] = "ODBC - Xtreme Sample Database 12";
                m_boAttributes["QE_SQLDB"] = true;
                m_boAttributes["Server Name"] = "Xtreme Sample Database 2008";
             

                //DAO
                //create logon attributes
                //m_boAttributes = new PropertyBag();
                //m_boAttributes["Database DLL"] = "crdb_dao.dll";
                //m_boAttributes["QE_DatabaseType"] = "Access";
                //m_boAttributes["QE_ServerDescription"] = "ODBC - Xtreme Sample Database 11.5";
                //m_boAttributes["QE_SQLDB"] = true;
                //m_boAttributes["Server Name"] = "C:\\Program Files\\Business Objects\\Common\\3.5\\Samples\\En\\Databases\\xtreme.mdb";
             

                //create connection info
                m_boConnectionInfo = new ConnectionInfo();

                m_boConnectionInfo.Attributes = m_boAttributes;
                m_boConnectionInfo.UserName = "Admin";
                m_boConnectionInfo.Password = "";
                m_boConnectionInfo.Kind = CrConnectionInfoKindEnum.crConnectionInfoKindSQL;
              

                //create a table
                m_boTable = new CrystalDecisions.ReportAppServer.DataDefModel.Table();
                m_boTable.ConnectionInfo = m_boConnectionInfo;
                m_boTable.Name = "Customer";
                m_boTable.Alias = "Customer";

                //add a table
                m_boReportClientDocument.DatabaseController.AddTable(m_boTable, null);

                //grab customer name
                iField = m_boReportClientDocument.Database.Tables[0].DataFields.Find("Customer Name", CrFieldDisplayNameTypeEnum.crFieldDisplayNameName, CeLocale.ceLocaleUserDefault);
                m_boFieldCustomer = (Field)m_boReportClientDocument.Database.Tables[0].DataFields[iField];
              

                //grab Last Years's Sale
                iField = m_boReportClientDocument.Database.Tables[0].DataFields.Find("Last Year's Sales", CrFieldDisplayNameTypeEnum.crFieldDisplayNameName, CeLocale.ceLocaleUserDefault);
                m_boFieldLastYSale = (Field)m_boReportClientDocument.Database.Tables[0].DataFields[iField];


                //grab city field
                iField = m_boReportClientDocument.Database.Tables[0].DataFields.Find("City", CrFieldDisplayNameTypeEnum.crFieldDisplayNameName, CeLocale.ceLocaleUserDefault);
                m_boFieldCity = (Field)m_boReportClientDocument.Database.Tables[0].DataFields[iField];

                //grab region field
                iField = m_boReportClientDocument.Database.Tables[0].DataFields.Find("Region", CrFieldDisplayNameTypeEnum.crFieldDisplayNameName, CeLocale.ceLocaleUserDefault);
                m_boFieldRegion = (Field)m_boReportClientDocument.Database.Tables[0].DataFields[iField];


                //grab country field
                iField = m_boReportClientDocument.Database.Tables[0].DataFields.Find("Country", CrFieldDisplayNameTypeEnum.crFieldDisplayNameName, CeLocale.ceLocaleUserDefault);
                m_boFieldCountry = (Field)m_boReportClientDocument.Database.Tables[0].DataFields[iField];

                //add database fields to report
                m_boReportClientDocument.DataDefController.ResultFieldController.Add(-1, m_boFieldCustomer);
                m_boReportClientDocument.DataDefController.ResultFieldController.Add(-1, m_boFieldLastYSale);
                m_boReportClientDocument.DataDefController.ResultFieldController.Add(-1, m_boFieldCity);
                m_boReportClientDocument.DataDefController.ResultFieldController.Add(-1, m_boFieldRegion);
                m_boReportClientDocument.DataDefController.ResultFieldController.Add(-1, m_boFieldCountry);

                //display in reportviewer
                crystalReportViewer1.ReportSource = m_boReportDocument;

    Keywords

    How create new report Crystal Reports .NET inproc RAS SDK , KBA , BI-DEV-NET , BI Software Development Kits (SDKs) - .NET or Other , How To

    Product

    SAP Crystal Reports XI R2