<%@ language= "VBSCRIPT"%>
<%
' = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
' Generate reports directly from the ADO recordset
' = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
'
Concept
'
' This application is designed to demonstrate how to generate reports from the ADO recordset. We first set up the ADO connection and
' Recordset object, and then generate a recordset from the database with an SQL statement. And then we build a crystal
' Reports object and point this object to the ADO recordset. Finally we will crystal Reports
' Smart Viewer is sent to the client to display this report.
' First step: Create the ADO Connection and Recordset
' An ADO database connection is accessed via an existing ODBC data source (DSN) from an application like ASP
' The connection of the data. To achieve the purpose of this example, we will use a Xtreme named "Sample Data"
' Connect to Access database Xtreme.mdb System DSN
' Create an ADO database connection:
Set oconn = Server.CreateObject ("ADODB. Connection ")
' Here we have an ADO connection called "oconn," which we'll connect to the above DSN with this ADO Connection object
' Use ADO connection must first open it:
oConn.Open ("Xtreme Sample Database")
' Here opens our ODBC data source, which points to an Access database Xtreme.mdb
' Now we have to create a Recordset object:
Set session ("ORs") = Server.CreateObject ("ADODB"). Recordset ")
' On top we set up a session ("ORs"). A Recordset object is stored in this session
' will contain the data returned with the SQL statement
' Define and generate a recordset:
Session ("ORs"). ActiveConnection = oconn
' Define the Connection object that this recordset will use
Session ("ORs"). Open SELECT [Product ID], [Product Name] from product
' Use SQL statements to remove two fields from the ' Product ' table in the Xtreme.mdb library
'===================================================================================
' Establish crystal Reports object
'===================================================================================
' You may notice that the Crystal reports object is set to session, because the requirement is called
' rptserver.asp ' ASP processing, in order for rptserver.asp to be able to easily access crystal,
' We set these objects to session. So that any ASP page runs in this session, you can access these objects directly
ReportName = "Adorecordset.rpt"
' Here, create a string variable, point to the Crystal (. rpt file), and then use this code
' Replace your crystal with the file name.
' Create a Application object
If not IsObject (session ("Oapp")) Then
Set session ("oapp") = Server.CreateObject ("Crystalruntime.application")
End If
' This ' if/end if ' structure is used to create Crystal Reports application objects per session only once O
' Set up Application Object-session ("Oapp"), will crystal the design of the bill Component
' Automation server (Craxdrt.dll) is loaded into memory.
'
We set up the session variables to use them in the ASP session. This will reduce the Craxdrt.dll
' Load and unload system overhead. Once a Application object is established in a session, we don't have to
' Rebuild the object to run more reports.
' Establish the object of the study
'
' The OpenReport method of the application was established
Path = Request.ServerVariables ("path_translated")
while (right (path, 1) <> "\" and Len (path) <> 0)
Ilen = Len (Path)-1
Path = Left (path, Ilen)
Wend
Response. Write Path
' This ' while/wend ' loop is used to convert the current file from the virtual path (Eg:http://domain/dir) to Crystal
' The physical path of the ' file ' (eg:c:\)
' Open the bill (remove any previous objects first)
If IsObject (Session ("Orpt")) Then
Set session ("orpt") = Nothing
End If
On Error Resume Next
Set session ("ORPT") = Session ("Oapp"). OpenReport (Path & ReportName, 1)
' Here, the physical path of the crystal file is computed and opened using the ' path ' and ' ReportName ' variables.
If err.number <> 0 Then
Response.Write "Error occurred creating": "& Err.Description
Set session ("orpt") = Nothing
Set session ("oapp") = Nothing
Session.Abandon
Response.End
End If
' This on Erro resume Next block checks for any errors that occur when you create a show object, and we are explicitly capturing any
' Error if the view exceeds the maximum number of concurrent users specified in the license agreement.
' Note that we are not only setting up a one-time object. This is because of the ASP session you can handle more than one report
' Rptserver.asp will only deal with a "session" ("Orpt") of the A. So if you want to work with multiple reports
' Then, a new session ("Orpt") object will be established.
' Error reporting mechanisms are not allowed here, including Crystal Report Design Component Automation server (Craxdrt.dll)
' Built-in error reporting, which is because of two reasons:
' 1. The print engine is executed on the Web server, so any error message will be displayed on the server, if an error is reported on the server side,
' The print engine will stop functioning and your application will be ' suspended '
' 2. Rptserver.asp already has some error handling logic inside, which can catch any non-fatal errors and appear on the client.
'
' * * IMPORTANT * Even if we prohibit error handling for server-side engines, fatal errors are captured on the Web server service side and
' Displays the Error prompt dialog box. So we suggest that you set up the world Wide Web Publishing Service (IIS service)
' Allow Service to interact with Desktop ' option. So if your ASP application dies, you will be able to see the error message.
' Now we have to tell the data in the ADO recordset
' The paper is built on the basis of the dynamic ADO recordset, and we have to build it based on the recordset we set up.
' Then at runtime we tell the data in the ADO record set. The paper usually relies on the database structure file
' (ADORECORDSET.TTX), this. ttx file contains the structure of the recordset and does not contain actual data.
' A crystal is completely dependent on the data structure of the will to be used, so at runtime your database structure file (TTX file)
' Or a real reaction to the DSN of the data contained in the ADO Recordset is very important
Session ("Orpt"). Discardsaveddata
Set Database = Session ("Orpt"). Database
' Instantiate the database used by the
Set Tables = Database.tables
' Instantiate a table in a database object
Set Table1 = Tables.item (1)
' Instantiate the first table, where this table object points to the Adorecordset.ttx file
Table1.setprivatedata 3, session ("ORs")
"SetPrivateData" tells the data source is the recordset, now the data will be displayed in the session ("ORs")
' If your report contains subreports, you will provide a different recordset to point to the subreport's data
'
'====================================================================================
' Re-log and build ' Page on Demand ' Engine Object
'====================================================================================
On Error Resume Next
Session ("Orpt"). ReadRecords
If err.number <> 0 Then
Response.Write "Error occurred Reading Records:" & Err.Description
Set session ("orpt") = Nothing
Set session ("oapp") = Nothing
Session.Abandon
Response.End
Else
If IsObject (Session ("Opageengine")) Then
Set session ("opageengine") = Nothing
End If
Set session ("Opageengine") = Session ("Orpt"). Pageengine
End If
' Materialized CRYSTAL REPORTS SMART VIEWER
'
' Using the Crystal Reports Automation server in an ASP environment, we use the same page to invoke the Crystal Web server
"Smart Viewers"
' There are four Crystal Reports Smart viewers:
'
' 1. ActiveX Smart Viewer
' 2. Java Smart Viewer
' 3. HTML Frame Smart Viewer
' 4. HTML Page Smart Viewer
'
' The Smart Viewer you use will be compatible with your number of browsers, for example, you won't be using the Java Viewer if your browser
' does not support Java applets. To this end, in this demo, we have chosen to define a viewer, you can use the code to determine
' Support compatibility for requesting browsers, however, this feature inherits from Crystal Reports Automation server,
' Beyond the scope of this example.
' For simple reasons, we have chosen to implement this functionality through the functionality included with the ASP server, you can choose a different
' Smartviewer*.asp files to different browsers, simply replace them with the smart Viewer ASP file you want to use.
' These choices are: smartvieweractivex.asp, smartviewerjave.asp,smartviewerhtmlframe.asp,
' and smartviewerhtmlpage.asp. Note that when you use these include files, you must put the corresponding. asp files in the same host
' ASP files in the same virtual path.
'
' * Note * for smartviewerhtmlframe and smartviewerhtmlpage, you must have framepage.asp in the virtual path
' Files and toolbar.asp files
Viewer = Request.Form ("viewer")
' Read the value of the viewer being used and put it in the variable viewer
If CStr (Viewer) = "ActiveX" Then
%>
<!--#include file= "smartvieweractivex.asp"-->
<%
ElseIf CStr (Viewer) = "Netscape Plug-in" Then
%>
<!--#include file= "activexpluginviewer.asp"-->
<%
ElseIf CStr (Viewer) = "Java using Browser JVM" then
%>
<!--#include file= "smartviewerjava.asp"-->
<%
ElseIf CStr (Viewer) = "Java using Java Plug-in" then
%>
<!--#include file= "javapluginviewer.asp"-->
<%
ElseIf CStr (Viewer) = "HTML Frame" Then
Response.Redirect ("htmstart.asp")
Else
Response.Redirect ("rptserver.asp")
End If
' The above If/then/else was designed to test the value of the "viewer" variable, and based on this value, send the appropriate Crystal Smart viewer
%>
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.