cancel
Showing results for 
Search instead for 
Did you mean: 

.net 2008 SP0 - ModifyGroup

Former Member
0 Kudos

Cannot get ModifyGroup to work in .net 2008 SP0.

' doc.DataDefController.GroupController.Modify(oldGroup, newGroup)

doc.DataDefController.GroupController.Modify(0, newGroup)

It throws "Invalid Group Number" exception

Accepted Solutions (0)

Answers (7)

Answers (7)

Former Member
0 Kudos

I really want to modify the existing group on the report so that summary fields on the report remain ok. It seems to work if the report was generated vs the same database but the .NET software doesn't work when the report was designed vs ORACLE and executed vs SQL SERVER. The RDC soffware handles this fine. My product supports ORACLE, SQL SERVER, and ACCESS and I have always been able to ship one set of reports that works with all three if I generate them pointed to an ORACLE database.

Former Member
0 Kudos

Hi Jim,

please see the new code which deletes the old group and adds a new cloned to it

Is this a possible workaround ?

Thanks

Falk

/********************************************************************
//File Name:     	CS_CreateReport_inproc.sln
//Created:       	November 19, 2008
//Author ID:     	FLI
//
//Purpose:       	This C# .NET sample Windows application demonstrates
//                  how to create a report, add several databasefields 
//                  and display this report using unmanaged inproc RAS.
//
// Note this is available without a dedicated RAS CR 2008
//********************************************************************


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


using CrystalDecisions.CrystalReports.Engine;


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace CS_CreateReport_inproc
{
    public partial class Form1 : Form
    {

        // CR variables
        ReportDocument m_boReportDocument;
        ISCDReportClientDocument m_boReportClientDocument;  // report client document

        PropertyBag    m_boLogonInfo;										// logon info
		PropertyBag    m_boAttributes;										// logon attributes
		ConnectionInfo m_boConnectionInfo;							    // connection info
		
        CrystalDecisions.ReportAppServer.DataDefModel.Table m_boTable;	// table
        CrystalDecisions.ReportAppServer.DataDefModel.Group boGroup;    // group
        CrystalDecisions.ReportAppServer.DataDefModel.Group boGroup2;   // group


		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 field        
      
        

        public Form1()
        {
            InitializeComponent();

            //*****************************
            // create a report from scratch
            //*****************************


            // -> no RAS server available
            
            //Create a new ReportDocument
            m_boReportDocument = new ReportDocument();

            // load the RPT file 
            m_boReportDocument.Load("..\\..\\dummy.rpt");

            //Access the ReportClientDocument in the ReportDocument (EROM bridge)
            m_boReportClientDocument = m_boReportDocument.ReportClientDocument;
            
            // <- no RAS server available



            // -> RAS server available
            /*
            // create report client document
            m_boReportClientDocument = new ReportClientDocument();

            // new report document
            m_boReportClientDocument.New();
            */
            // <- RAS server available


          
            // 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 11.5";
            m_boAttributes["QE_SQLDB"] = true;
            m_boAttributes["Server Name"] = "Xtreme Sample Database 11.5";
           */

            // 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";
            m_boAttributes["Server Name"] = "C:\\Program Files\\Microsoft Visual Studio 9.0\\Crystal Reports\\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);

            //Create a new Group Object
            boGroup = new CrystalDecisions.ReportAppServer.DataDefModel.Group();

            //Set that field as the field to group on
            boGroup.ConditionField = m_boFieldCountry;

            //And finally Add it to the report
            m_boReportClientDocument.DataDefController.GroupController.Add(-1, boGroup);



            // show in reportviewer
            // -> no RAS server available
            crystalReportViewer1.ReportSource = m_boReportDocument;

            // -> RAS server available
            //crystalReportViewer1.ReportSource = m_boReportClientDocument;

        }

        private void button1_Click(object sender, EventArgs e)
        {
            m_boReportDocument.SaveAs("C:\\Test.rpt");
        }

        private void button2_Click(object sender, EventArgs e)
        {
            // grab country field
            iField = m_boReportClientDocument.Database.Tables[0].DataFields.Find("Region", CrFieldDisplayNameTypeEnum.crFieldDisplayNameName, CeLocale.ceLocaleUserDefault);
            m_boFieldRegion = (Field)m_boReportClientDocument.Database.Tables[0].DataFields[iField];


            ////Clone the  Group Object
            boGroup2 = boGroup.Clone(true);


            //Set that field as the field to group on
            boGroup2.ConditionField = m_boFieldRegion;

            //Remove the old group the report
            m_boReportClientDocument.DataDefController.GroupController.Remove(boGroup);

            //And finally Add the new group to the report
            m_boReportClientDocument.DataDefController.GroupController.Add(-1, boGroup2);

            // show in reportviewer
            // -> no RAS server available
            crystalReportViewer1.ReportSource = m_boReportDocument;
        }        
    }
}

Former Member
0 Kudos

I have exactly the same problem and the same situation (reports updated from 8.5 to XI plus clients designing their own reports in various versions of Crystal (none older than 8.5 though)) though I have tried using CR 2008 SP1 RAS .Net components. If the report is built from scratch using Crystal 2008 designer then I can modify the group programmatically but otherwise not. I assume this is a bug in the CR components - do you know if this is being fixed and if so when it might be available (SP2? Any date for it?). I am changing from COM RDC (where you could programmatically modify the SQL of a report) to .NET RAS as RDC is no longer supported. I read the sql using RAS, modify the sql in c#, make a new command object with the modified sql and modify all fields, sorts, record selections and groups to point to the new command table before removing the existing tables in the report. Just the group problem is the sticking point. I have already read the dead thread [|]. Any help/info would be much appreciated. Many thanks and kind regards, Sascha

Former Member
0 Kudos

Hello Sascha,

I sent you the code already to our direct mail account but for other customer the full source here :

This CS code creates a report on the fly and adds a group on one field.

It works with VS 2008 and CR 2008 SP1

//********************************************************************
//File Name:     	CS_CreateReport_inproc.sln
//Created:       	November 19, 2008
//Author ID:     	FLI
//
//Purpose:       	This C# .NET sample Windows application demonstrates
//                  how to create a report, add several databasefields 
//                  and display this report using unmanaged inproc RAS.
//
// Note this is available without a dedicated RAS CR 2008
//********************************************************************


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


using CrystalDecisions.CrystalReports.Engine;


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace CS_CreateReport_inproc
{
    public partial class Form1 : Form
    {

        // CR variables
        ReportDocument m_boReportDocument;
        ISCDReportClientDocument m_boReportClientDocument;  // report client document

        PropertyBag    m_boLogonInfo;										// logon info
        PropertyBag    m_boAttributes;										// logon attributes
        ConnectionInfo m_boConnectionInfo;							    // connection info
		
        CrystalDecisions.ReportAppServer.DataDefModel.Table m_boTable;	// table
        CrystalDecisions.ReportAppServer.DataDefModel.Group boGroup;    // group


        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 field        
      
        

        public Form1()
        {
            InitializeComponent();

            //*****************************
            // create a report from scratch
            //*****************************


            // -> no RAS server available
            
            //Create a new ReportDocument
            m_boReportDocument = new ReportDocument();

            // load the RPT file 
            m_boReportDocument.Load("..\\..\\dummy.rpt");

            //Access the ReportClientDocument in the ReportDocument (EROM bridge)
            m_boReportClientDocument = m_boReportDocument.ReportClientDocument;
            
            // <- no RAS server available



            // -> RAS server available
            /*
            // create report client document
            m_boReportClientDocument = new ReportClientDocument();

            // new report document
            m_boReportClientDocument.New();
            */
            // <- RAS server available


          
            // 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 11.5";
            m_boAttributes["QE_SQLDB"] = true;
            m_boAttributes["Server Name"] = "Xtreme Sample Database 11.5";
           */

            // 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\\Microsoft Visual Studio 9.0\\Crystal Reports\\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);

            //Create a new Group Object
            boGroup = new CrystalDecisions.ReportAppServer.DataDefModel.Group();

            //Set that field as the field to group on
            boGroup.ConditionField = m_boFieldCountry;

            //And finally Add it to the report
            m_boReportClientDocument.DataDefController.GroupController.Add(-1, boGroup);



            // show in reportviewer
            // -> no RAS server available
            crystalReportViewer1.ReportSource = m_boReportDocument;

            // -> RAS server available
            //crystalReportViewer1.ReportSource = m_boReportClientDocument;

        }

        private void button1_Click(object sender, EventArgs e)
        {
            m_boReportDocument.SaveAs("C:\\Test.rpt");
        }        
    }
}

Former Member
0 Kudos

I tried the update with CR 2008 already and it didn't help. I have many reports that have been created with mostly Crystal 8.5 and then updated with Crystal 10. I also have many customers that have purchased Crystal and then modified and created reports that I don't have access to. I created an new very simple report with Crystal 10 that confirms the problem.

Former Member
0 Kudos

Ted, I just tried this with a report created with Crystal Reports 2008 and it works like you said. It won't work with reports created with older versions of Crystal Reports.

ted_ueda
Active Contributor
0 Kudos

That's interesting.

What if you take the report, open it in Crystal Reports 2008 and save it, then try the code?

Which version are the older ones?

Sincerely,

Ted Ueda

Former Member
0 Kudos

Does ModifyGroup change the corresponding Sort or do they each need to be modified?

ted_ueda
Active Contributor
0 Kudos

Hello Jim,

Was training last week.

The code snippet I had in your previous post works on my VS 2005 with Crystal Reports 2008 SP0 as well.

Sincerely,

Ted Ueda

former_member183750
Active Contributor
0 Kudos

Please see this thread:

https://forums.sdn.sap.com/click.jspa?searchID=16351851&messageID=6008570

Perhaps it will help.

Ludek