1605746 - How to convert a database table to a command object using the RAS SDK for .NET

SAP Knowledge Base Article - Public

1605746 - How to convert a database table to a command object using the RAS SDK for .NET

Symptom

sql CR Crystal Reports dot

Resolution

  • The bellow code will convert one table to a command object
  • The code can be extended to tow tables
  • Note that two tables is the limit
private void TableToCommand_Click(object sender, EventArgs e)
        {
            CrystalDecisions.CrystalReports.Engine.ReportDocument rpt = new CrystalDecisions.CrystalReports.Engine.ReportDocument();
            ISCDReportClientDocument rcd;
 
            rcd = rptClientDoc;
 
            rptClientDoc.DatabaseController.LogonEx("ServerName", "xtreme", "sa", "pw");
 
            CrystalDecisions.ReportAppServer.DataDefModel.ConnectionInfo oldConninfo;
            CrystalDecisions.ReportAppServer.DataDefModel.ConnectionInfo newConnInfo = new CrystalDecisions.ReportAppServer.DataDefModel.ConnectionInfo();
            CrystalDecisions.ReportAppServer.DataDefModel.Table oldTbl;
            CrystalDecisions.ReportAppServer.DataDefModel.CommandTable newTbl = new CommandTable();
 
            oldTbl = (CrystalDecisions.ReportAppServer.DataDefModel.Table)rcd.Database.Tables[0];
            oldConninfo = oldTbl.ConnectionInfo.Clone(true);
 
            GroupPath gp = new GroupPath();
            gp.FromString("");
            string sql = String.Empty;
            rptClientDoc.RowsetController.GetSQLStatement(gp, out sql);
 
            PropertyBag QEProps = new PropertyBag();
            PropertyBag logonProps = new PropertyBag();
 
            //Set the attributes for the logonPropsBag
            logonProps.Add("Database", "xtreme");
            logonProps.Add("DSN", "ServerName");
            logonProps.Add("UseDSNProperties", "False");
 
            //Set the attributes
            QEProps.Add("Database DLL", "crdb_odbc.dll");
            QEProps.Add("QE_DatabaseName", "xtreme");
            QEProps.Add("QE_DatabaseType", "ODBC (RDO)");
 
            //Add the QE_LogonProperties we set in the logonProps Object
            QEProps.Add("QE_LogonProperties", logonProps);
            QEProps.Add("QE_ServerDescription", "ServerName");
            QEProps.Add("QE_SQLDB", "True");
            QEProps.Add("SSO Enabled", "False");
 
            newConnInfo.Attributes = QEProps;
            newConnInfo.UserName = "sa";
            newConnInfo.Password = "pw";
            newConnInfo.Kind = CrConnectionInfoKindEnum.crConnectionInfoKindCRQE;
 
            newTbl.ConnectionInfo = newConnInfo;
            newTbl.CommandText = sql;
            newTbl.Name = "Command";
           
       //     foreach(CrystalDecisions.ReportAppServer.DataDefModel.Table tbl in rcd.Database.Tables)
            {
                rcd.DatabaseController.SetTableLocationEx(oldTbl,newTbl);
                oldTbl =(CrystalDecisions.ReportAppServer.DataDefModel.Table) rcd.Database.Tables[0].Clone(true);
                rcd.DatabaseController.SetTableLocationEx(oldTbl, newTbl);
            }
 
            // save the report to a new folder
        }

Keywords

KBA , BI-DEV-NET-SDK , .NET SDK / COM SDK , How To

Product

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