cancel
Showing results for 
Search instead for 
Did you mean: 

Crystal Reports Dynamic Changing of Data Source

Former Member
0 Kudos

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

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

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]

Former Member
0 Kudos

Sir, thank you very much for your reply. The sample codes were very much helpful. I could now successfully change data source dynamically.

But still, I encounter error messages: JRCAgent1 detected an exception: No results were returned by the query.

which leads me to conclusion that, the parameters are "left out"

Former Member
0 Kudos

I would just like to add that I use Stored Procedure for querying the results. I hope this could be a help in figuring out my problem.

Thanks again

Former Member
0 Kudos

Hmmm, in that case use the following sample:

[http://www.sdn.sap.com/irj/boc/index?rid=/library/uuid/40c2b287-3f11-2c10-d8af-9be95b69fe82]

Former Member
0 Kudos

Sir, thanks for your reply again. But Im encountering an error im not familiar with:

Failed to load the resource 'ProgrammingError' from the bundle java.util.PropertyResourceBundle@17b1c02.

java.util.MissingResourceException: Can't find resource for bundle java.util.PropertyResourceBundle, key ProgrammingError

This occurs in .setTableLocation() line.

Please excuse my ignorance. Thank you very much again

Former Member
0 Kudos

Found out what causing the error. Its from a wrong Stored Procedure Name I passes (Forgive me for that).

What I did next was to set the parameters for the Stored Procedure via the ff codes:

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

IProcedure table = (IProcedure)tables.getTable(i);

table.setName(spName);

table.setAlias(spName);

table.setParameters(params);

...

}

Im now having this error: JRCAgent1 detected an exception: Unknown EROM field value type

Answers (2)

Answers (2)

Former Member
0 Kudos

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...

Former Member
0 Kudos

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]