Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Скачиваний:
81
Добавлен:
11.05.2015
Размер:
2.11 Mб
Скачать

4Click Open in the Select Database File dialog box, and the path and file name of the database you selected appear in the DAO text box on the Select Data Source dialog box.

5Click Next, and the Select Recordset dialog box appears.

6If the database requires log on information, specify a user name and password to log on.

7Determine if you want to create a Recordset using an object available from your database, such as a database table, or if you prefer to specify a SQL statement. Select the appropriate option in the Recordset section of the Select Recordset dialog box.

8If you want to connect to a database object, use the Object Type drop-down list box to select the type of database object, such as a Table, then select the object itself from the Object drop-down list box.

9If you want to obtain a Recordset using a SQL statement, write the SQL statement in the text box provided and click Next.

10Click Finish in the Select Recordset dialog box. You will see dao in the list box on the Data Tab of the Report Expert.

11Continue creating your report normally. While creating your report, the dao specification will act like a database table, providing all fields that have been obtained from your DAO Recordset.

Crystal Data Object

The Crystal Data Object (CDO) is an ActiveX data source that allows you to define fields and records at runtime based on data that exists only at runtime. Through CDO, any data can become a virtual database and can be reported on using the power of the Crystal Report Engine.

CDO, like DAO and ADO, is based on the Component Object Model (COM). Any development environment that supports COM interfaces can dynamically generate a set of data for a report without relying on a database that exists at design time.

Applications that produce data that does not exist outside of the running application have been unable, until now, to take advantage of the most powerful reporting features in the industry. CDO, however, solves that problem. For instance, applications that monitor system or network resources, or any constantly operating environment, can produce a current report on such information at any time. No longer does data need to be dumped to a separate database before analysis. Through CDO, the Active Data Driver, and the Crystal Report Engine, analysis is instant and up-to-date.

The following topics are discussed in this section.

CDO vs. the Crystal Data Source Type Library, Page 129

Using the Crystal Data Object, Page 129

Crystal Data Object Model, Page 131

Visual Basic Solutions

128

CDO vs. the Crystal Data Source Type Library

Seagate Crystal Reports also supports the Crystal Data Source Type Library, Page 131, for implementing in a Visual Basic class definition. Crystal Data Source objects can also be passed to the Active Data Driver as ActiveX data sources. However, the Crystal Data Source Type Library exposes a complete COM interface that must be implemented in your class. CDO, on the other hand, provides a fast and simple method for producing an internal customized ActiveX data source.

If you need to implement a complete data source in your application that allows runtime movement through records and fields, or if you intend to implement your data source as a separate ActiveX component, consider using the Crystal Data Source Type Library. However, if you need to create a quick and simple means of storing a large amount of data in a convenient package for reporting on, and the data will remain inside the same application as the reporting functionality, then use Crystal Data Objects.

Using the Crystal Data Object

The Crystal Data Object is an ActiveX DLL that can be accessed from any Windows development environment that supports ActiveX. By creating a Rowset object, similar to a Recordset, and filling it with fields and data, you design a virtual database table that can be passed as an ActiveX data source to the Crystal Active Data Driver.

Once the CDO Rowset has been created, it can be used just like any other active data source such as DAO or ADO. Use a procedure, much like the procedure described in Using the Active Data Driver, Page 119, to print, preview, or export a report at runtime that is based on the CDO data source. Simply replace the steps that explain how to pass a DAO Recordset to the Active Data Driver with appropriate steps for passing your CDO Rowset.

The rest of this section explains how to create a CDO Rowset in Visual Basic. However, as an ActiveX DLL, CDO can be used by any application development environment that supports ActiveX.

To create a CDO Rowset:

1.Obtain a CDO Rowset Object, Page 129

2.Add Fields to the Rowset Object, Page 130

3.Obtain Data as Rows, Page 130

4.Add Rows to the Rowset Object, Page 131

Use these steps as a guideline for creating your own CDO Rowsets for use with the Active Data Driver.

Obtain a CDO Rowset Object

As stated earlier, CDO is a standard automation server. A Rowset object can be obtained from CDO using the Visual Basic CreateObject function:

Public CDOSet As Object

Set CDOSet = CreateObject(“CrystalDataObject.CrystalComObject”)

This Rowset object is, essentially, equivalent to a Recordset object you might obtain from DAO or another active data source. It is the Rowset object that you eventually pass to the Active Data Driver.

Visual Basic Solutions

129

Add Fields to the Rowset Object

Once you have a Rowset object, you need to define fields for the Rowset. These fields act as the virtual database fields. The field names you specify must match the field names specified in the data definition file. For more information on data definition files, see Creating Data Definition Files, Page 123.

Fields are added to a CDO Rowset using the AddField method:

CDOSet.AddField “Order ID”, vbString

CDOSet.AddField “Company Name”, vbString

CDOSet.AddField “Order Date”, vbDate

CDOSet.AddField “Order Amount”, vbCurrency

This code adds four fields to the Rowset with the specified field names, and field types. The field types are based on constant values for the Variant data type. The constant names used here are from Visual Basic. For information on valid constant values, see the AddField method in the Crystal Data Object Reference in Developer’s online Help.

Obtain Data as Rows

Data to be added as rows in the Rowset can be collected in a two dimensional array. The first dimension indicates rows, while the second dimension specifies fields for each row. The number of possible fields indicated by the second dimension must not exceed the number of fields you added to the Rowset using the AddField method. For example, you might define an array such as this:

Dim Rows(12, 4) As Variant

This specifies an array named Rows that contains 12 rows (0 to 11) and 4 columns (0 to 3). Notice that the four fields are defined with the AddField method, so the 4 columns in the Rows array are also defined. In addition, room has been made for 12 rows or records. Finally, since each field holds a different type of data, the array is defined as a Variant type.

NOTE: If your Rowset contains only a single field, you can use a one dimensional array instead of two dimensional. The single dimension indicates the number of rows or records in your Rowset.

Now that you have defined an array to hold data, you can begin adding values to the array. These array values will become the actual field values for the virtual database. Most likely, you will want to design a routine in your application that adds runtime data generated by your application into each cell of the array. The following code, however, demonstrates how you can explicitly add values to the array:

Rows(0, 0)

= “1002” ’The first Order ID

 

Rows(0, 1)

= “Cyclist's Trail Co.” ’The

first Company Name

Rows(0,

2)

=

#12/2/94# ’The

first

Order

Date

Rows(0,

3)

=

5060.2725 ’The

first

Order

Amount

From here, you could continue by adding a value to the first field of the second record, Rows (1, 0). You continue filling in data record by record and field by field. This technique, of course, requires a lot of code and is not very practical. Most real applications would contain a looping procedure that progressively filled in values for the array.

Visual Basic Solutions

130

Соседние файлы в папке crystal