on 10-03-2008 11:06 AM
Hi All,
now in my web application I am facing the problem of
Table cannot get added by using following script.
any one told me please.
<%@ page contentType="text/html; charset=utf-8"%>
<%@ page import="com.crystaldecisions.sdk.occa.report.application.DatabaseController" %>
<%@ page import="com.crystaldecisions.sdk.occa.report.application.ReportClientDocument" %>
<%@ page import="com.crystaldecisions.sdk.occa.report.data.Field" %>
<%@ page import="com.crystaldecisions.sdk.occa.report.data.Table" %>
<%@ page import="com.crystaldecisions.sdk.occa.report.data.TableLink" %>
<%@ page import="com.crystaldecisions.sdk.occa.report.data.TableLinks" %>
<%@ page import="com.crystaldecisions.sdk.occa.report.lib.ReportSDKException" %>
<%@ include file = "Utilities.jsp" %>
<%
/*
This page creates a new report based on the tables, linking fields, and name provided by the
user on previous pages.
*/
%>
<%!
/*
This function adds the two given tables to the report and then links them
using the two given field names.
Parameters:
reportClientDocument
The ReportClientDocument object to which the new tables will be added.
It is assumed that the report does not have any tables.
sourceTable
The Table object representing the source table used for the linking.
targetTable
The Table object representing the target table used for the linking.
sourceFieldName
A name of a field from the source table. This field will be used for linking.
targetFieldName
A name of a field from the source table. This field will be used for linking.
Returns: void
*/
void addAndLinkTables( ReportClientDocument reportClientDocument,
Table sourceTable, Table targetTable,
String sourceFieldName, String targetFieldName )
throws TutorialException
{
/*
Only the database controller can be used to modify a report's table structure.
Here it is used add the two tables to the report.
*/
DatabaseController databaseController;
try
{
databaseController = reportClientDocument.getDatabaseController();
databaseController.addTable(sourceTable, new TableLinks());
databaseController.addTable(targetTable, new TableLinks());
}
catch(ReportSDKException e)
{
throw new TutorialException("Error while adding tables.");
}
// Create the new link that will connect the two tables.
TableLink tableLink = new TableLink();
/*
Add the source field name and the target field name to the SourceFieldNames
and TargetFieldNames collection of the TableLink object.
*/
tableLink.getSourceFieldNames().add(sourceFieldName);
tableLink.getTargetFieldNames().add(targetFieldName);
/*
Specify which tables are to be linked by setting table aliases
for the TableLink object.
*/
tableLink.setSourceTableAlias(sourceTable.getAlias());
tableLink.setTargetTableAlias(targetTable.getAlias());
// Add the link to the report. Doing so effectively links the two tables.
try
{
databaseController.addTableLink(tableLink);
}
catch(ReportSDKException e)
{
throw new TutorialException("Error while linking tables.");
}
}
%>
<%
// Get the previously opened report from the session.
ReportClientDocument sourceReportClientDocument =
(ReportClientDocument)session.getAttribute("ReportClientDocument");
// Create a new report.
ReportClientDocument newReportClientDocument = createNewReport(session);
// Retrieve the names of the tables from the session.
Table sourceTable = (Table)session.getAttribute("SourceTable");
Table targetTable = (Table)session.getAttribute("TargetTable");
// Retrieve the names of the linking fields from the session.
String sourceFieldName = (String)session.getAttribute("SourceFieldName");
String targetFieldName = (String)session.getAttribute("TargetFieldName");
// Retrieve the name of the new report.
String newReportName = request.getParameter("NewReportName");
// Add and link the tables, and then save the report.
try
{
addAndLinkTables( newReportClientDocument, sourceTable, targetTable,
sourceFieldName, targetFieldName );
saveReportAs(newReportClientDocument, newReportName, session);
}
catch (TutorialException e)
{
redirectWithError("Error.jsp", e.getMessage(), response);
return;
}
// Close both the source report and the new report.
closeReport(sourceReportClientDocument, session);
closeReport(newReportClientDocument, session);
%>
<html>
<head>
<link rel='stylesheet' type='text/css' name='stylelink' href='../tutss.css'>
</head>
<body>
<hr>
<p>The new report <i><%= newReportName %></i> has been saved.</p>
<hr>
</body>
</html>
Please find below a snippet code based on the java managed RAS api. It adds table. Try adding the code to logon to the Enterprise and try it.
ReportClientDocument oReportClientDocument;
IReportAppFactory oReportAppFactory;
IInfoObjects oInfoObjects=null;
IInfoObject oInfoObject=null;
String reportName = "SimpleRCAPIReport.rpt";
// Retrieve report to be modified
oInfoObjects = iStore.query("Select * from CI_INFOOBJECTS where SI_PROGID = 'CrystalEnterprise.Report' and SI_INSTANCE = 0 and SI_NAME = '" + reportName + "'");
oReportAppFactory = (IReportAppFactory)es.getService("", "RASReportService");
oReportClientDocument = oReportAppFactory.openDocument((IInfoObject)oInfoObjects.get(0), 0, java.util.Locale.ENGLISH);
// This will add a database table using an ODBC connection. Since the report already has the Customer Table, we will add the Orders Table
// Specify the database dll to be used
String database_dll = "crdb_odbc.dll";
// Create the DB connection
ConnectionInfo oConnectionInfo = new ConnectionInfo();
PropertyBag oPropertyBag1 = oConnectionInfo.getAttributes();
// Set new table logon properties
PropertyBag oPropertyBag2 = new PropertyBag();
oPropertyBag2.put("DSN", "Xtreme Sample Database 11.5");
// Because this is an ODBC connection to an access database, there is no need to specify the database
oPropertyBag2.put("Data Source", "");
// Set the connection info objects members
// 1. Pass the Logon Properties to the main PropertyBag
// 2. Set the Server Description to the new **System DSN**
oPropertyBag1.put(PropertyBagHelper.CONNINFO_CRQE_LOGONPROPERTIES, oPropertyBag2);
oPropertyBag1.put(PropertyBagHelper.CONNINFO_CRQE_SERVERDESCRIPTION, "Xtreme Sample Database 11.5");
oPropertyBag1.put("Database DLL", database_dll);
oConnectionInfo.setAttributes(oPropertyBag1);
// Blank username and password since this database does not require them
oConnectionInfo.setUserName("");
oConnectionInfo.setPassword("");
// The Kind of connectionInfos is CRQE (Crystal Reports Query Engine).
oConnectionInfo.setKind(ConnectionInfoKind.CRQE);
// Now create and add the table
Table oTable;
String table_name = "Orders";
oTable = new Table();
oTable.setName(table_name);
oTable.setConnectionInfo(oConnectionInfo);
oReportClientDocument.getDatabaseController().addTable(oTable, null);
// Now display the report - you will need to export the report to see the added table.
session.setAttribute("reportSource", oReportClientDocument.getReportSource());
response.sendRedirect("CrystalReportViewer.jsp");
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
79 | |
10 | |
9 | |
7 | |
6 | |
6 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.