You can change the user name and password to a
subreport, or set its database to a different location, using the
ReportClientDocument class. It
lets you retrieve the database object for a subreport, which contains tables
from one or more databases. Using this object, you can change the subreport
logon information.
Specify the name of the subreport
to logon to.
String subreportName = "subreport.rpt";
Get the subreport database by using
the
getSubreportDatabase method of
the
SubreportController object.
IDatabase database = rcd.getSubreportController().getSubreportDatabase(subreportName);
Get a database table.
This sample gets the first
database table.
Table table = (Table)database.getTables().getTable(0);
Create a copy of the table by
calling the
clone
method.
Table newTable = (Table)table.clone(false);
Set the logon properties of the
table.
newTable.getConnectionInfo().setUserName("username");
newTable.getConnectionInfo().setPassword("password"); Set the table location for the
subreport by replacing the original table with the new table that contains the
logon information.
rcd.getSubreportController().setTableLocation(subreportName, table, newTable);
Example: To logon to a subreport
void logonSubreport(ReportClientDocument rcd) throws ReportSDKException
{
String subreportName = "subreport.rpt";
IDatabase database = rcd.getSubreportController().getSubreportDatabase(subreportName);
Table table = (Table)database.getTables().getTable(0);
Table newTable = (Table)table.clone(false);
newTable.getConnectionInfo().setUserName("username");
newTable.getConnectionInfo().setPassword("password");
rcd.getSubreportController().setTableLocation(subreportName, table, newTable);
}This list includes the classes used by the sample
code:
com.crystaldecisions.sdk.occa.report.application.ReportClientDocument
com.crystaldecisions.sdk.occa.report.data.IDatabase
com.crystaldecisions.sdk.occa.report.data.Table
com.crystaldecisions.sdk.occa.report.lib.ReportSDKException
java.lang.String