8 Replies Latest reply: Sep 28, 2009 11:24 AM by Gary Villavicencio RSS

Crystal Reports Dynamic Changing of Data Source

Gary Villavicencio
Currently Being Moderated

Good day Sirs:

 

this is my first post here, should i violate any rules, please accept my humblest apologies.

 

I would like to ask your help regarding my problem. Im using Eclipse Europa and Crystal Reports XI. What I would like to do is to dynamically change the DataSource of my Crystal Report. I believe I have done that with the following codes:

 

Tables tables = rptClientDoc.getDatabaseController().getDatabase().getTables();

      

        for (int i = 0; i < tables.size(); i) {

            ITable origTable = tables.getTable(i);

            ITable newTable =(ITable)((IClone) origTable).clone(true);

          

            +newTable.setName(DB_SCHEMA + newTable.getName());+

            newTable.setAlias(newTable.getAlias());

          

            origTable.setQualifiedName(newTable.getName());

 

            IConnectionInfo connectionInfo = newTable.getConnectionInfo();

          

            PropertyBag propertyBag = new PropertyBag();

          

            propertyBag.put("Trusted_Connection", "false");

            propertyBag.put("Server Name", SERVER_NAME);

             

            propertyBag.put("Connection String", CONNECTION_STRING);

            propertyBag.put("Database Name", DB_NAME);

            propertyBag.put("Server Type", "JDBC (JNDI)");

            propertyBag.put("URI", URI);

            propertyBag.put("Use JDBC", "true");

            propertyBag.put("Database DLL", DB_DLL);

            connectionInfo.setAttributes(propertyBag);

          

              

            rptClientDoc.getDataDefController().getDataDefinition().getParameterFields();

          

            connectionInfo.setUserName(USER_NAME);

            connectionInfo.setPassword(USER_PWD);

            connectionInfo.setKind(ConnectionInfoKind.SQL);

            newTable.setConnectionInfo(connectionInfo);

          

            rptClientDoc.getDatabaseController().setTableLocation(origTable,newTable);

        }

 

But I recieve this Error Message: JRCAgent1 detected an exception: No results were returned by the query.

 

It seems that my Parameters are not seen by the query, having this code:

 

ParameterFieldController paramFieldController = rptClientDoc.getDataDefController().getParameterFieldController();

Fields params = rptClientDoc.getDataDefController().getDataDefinition().getParameterFields();

        for (int j = 0; j < params.size(); j++) {

            IParameterField parameterField = (IParameterField) params.getField(j);

          

        }

 

Your help will be a great lift to my dipping morale...

 

Thank you very much and I hope to hear from anybody soon...

 

Edited by: grayscale on Sep 28, 2009 8:34 AM

  • Re: Crystal Reports Dynamic Changing of Data Source
    Currently Being Moderated

    Please download the following sample and modify the code according to your requirement:

     

    [http://www.sdn.sap.com/irj/boc/index?rid=/library/uuid/f0ad3d3d-be66-2b10-2181-f46c6e05a420]

  • Re: Crystal Reports Dynamic Changing of Data Source
    Gary Villavicencio
    Currently Being Moderated

    Good day Sirs:

     

    this is my first post here, should i violate any rules, please accept my humblest apologies.

     

    I would like to ask your help regarding my problem. Im using Eclipse Europa and Crystal Reports XI. What I would like to do is to dynamically change the DataSource of my Crystal Report. I believe I have done that with the following codes:

     

    Tables tables = rptClientDoc.getDatabaseController().getDatabase().getTables();

               

    for (int i = 0; i < tables.size(); i++) {

         ITable origTable = tables.getTable(i);

         ITable newTable =(ITable)((IClone) origTable).clone(true);

                         

         newTable.setName(DB_SCHEMA + newTable.getName());

         newTable.setAlias(newTable.getAlias());

                    

         origTable.setQualifiedName(newTable.getName());

     

         IConnectionInfo connectionInfo = newTable.getConnectionInfo();

                    

         PropertyBag propertyBag = new PropertyBag();

                    

          

         propertyBag.put("Trusted_Connection", "false");

         propertyBag.put("Server Name", SERVER_NAME); //Optional property.

         propertyBag.put("Connection String", CONNECTION_STRING);

         propertyBag.put("Database Name", DB_NAME);

         propertyBag.put("Server Type", "JDBC (JNDI)");

         propertyBag.put("URI", URI);

         propertyBag.put("Use JDBC", "true");

         propertyBag.put("Database DLL", DB_DLL);

         connectionInfo.setAttributes(propertyBag);

                                   

         connectionInfo.setUserName(USER_NAME);

         connectionInfo.setPassword(USER_PWD);

         connectionInfo.setKind(ConnectionInfoKind.SQL);

         newTable.setConnectionInfo(connectionInfo);

                                        

          

         rptClientDoc.getDatabaseController().setTableLocation(origTable,newTable);

                    

    }

     

     

    But still recieve messages and I think I am missing the Parameters though I have set it via this code:

     

    ParameterFieldController paramFieldController = rptClientDoc.getDataDefController().getParameterFieldController();

    Fields params = rptClientDoc.getDataDefController().getDataDefinition().getParameterFields();

            for (int j = 0; j < params.size(); j++) {

                IParameterField parameterField = (IParameterField) params.getField(j);

              

            }

     

    Your help will be a great lift to my dipping morale...

     

    Thank you very much and I hope to hear from anybody soon...

  • Re: Crystal Reports Dynamic Changing of Data Source
    Currently Being Moderated

    Please download the following sample and modify the code according to your requirement:

     

    [http://www.sdn.sap.com/irj/boc/index?rid=/library/uuid/f0ad3d3d-be66-2b10-2181-f46c6e05a420]

Actions