Crystal Reports Online Training

Learn Online, Anytime, Anywhere

Step-by-step online tutorials.

13.02 Pull Model

Implementing the Pull Model

The Report Expert uses the simplest form of the Pull Model to create reports. Within the Report Expert is the Database Expert, where the data source(s) that the report connects to and the tables that have the data are defined. The Report Expert, generates a default report layout and builds, behind the scenes, all the data connections necessary. The only thing you have to do is call the proper method to either preview or print the report. All the examples in the book prior to this chapter used the Pull Model. This was done so that you could focus on report design and layout issues, unencumbered with worries about the intricacies of database. As you can see, implementing the examples didn’t require any knowledge about data connectivity.

However, there are three aspects to the Pull Model you need knowledge of. They are: adding a data source, linking tables, and using multiple data sources.

Adding Data Sources

The Pull Model uses the Database Expert dialog box as the interface for selecting data sources for your report. It is a visual expert for opening data sources, finding tables within the data sources, and linking their related fields together. To get to it, run the Report Expert, or right-click on an existing report in design mode and select Database | Add/Change Database.

The Database Expert uses two tabs: the Data tab and the Links tab. The Data tab, shown in Figure 13-1, is the way to add data sources to the report. It shows two windows: Available Data Sources and Selected Data Sources.



Figure 13-1. The Data Tab of the Database Expert.

The Available Data Sources window lists different categories of data sources. Table 14.1 lists these available data source categories.

Table 13-1. Available Data Sources

Data Source Description
ADO.NET DataSets Found within the Project Data category, these are the DataSet classes listed in the Visual Studio Project Explorer window. They give you the flexibility to tie your report to virtually any type of data.
Current Connections Found within the Project Data category, select from any connections already established within the Server Explorer.
OLE DB (ADO) Builds a connection string to access data sources using an OLE DB driver. It gives you a two screen wizard which asks you for the data source to connect to and any relevant information regarding its location and logon information.
ODBC (RDO) Connect using an ODBC driver by selecting an existing System DSN.
Database Files Select a PC database file using its file location.
Favorites Choose from commonly used data sources you added to your Favorites list. Existing items can be added to the favorites list by right-clicking on them and selecting Add To Favorites. A Favorite can be renamed by clicking on it and pressing the F2 key.
History Choose from data sources that have been used for other reports within the current project.
ADO.NET (XML) Found within the More Data Sources category, it retrieves records by specifying an XML file path. You can also select an existing ADO.NET dataset.
Access/Excel (DAO) Found within the More Data Sources category, it retrieves records using a DAO recordset that accesses a Microsoft Access database or Excel spreadsheet.
Field Definitions Only Found within the More Data Sources category, it specifies a field definition file. Per the documentation, this is only for backwards compatibility and isn’t used for new development.

To select the data source from the Database Expert dialog, click on the proper category node to expand it. This triggers a dialog box which asks for information about the data source. The dialog changes to match the needs of each data source. This information can range from a simple file path to a database server name and the appropriate logon credentials. Upon entering the information, the dialog box closes and the data source name is shown in the Database Expert and listed under its category. Under the data source name is the list of available tables, views and stored procedures. Click on the plus signs next to the individual items to expand the list.

Add the tables you need to your report by selecting them and clicking on the Add Table button. Double-clicking on the table will also add it to the list. When all have been added, go to the Links tab to establish the relationship between the tables.

There is one small quirk about the Available Data Sources window you should be aware of. It occurs when you click on the plus sign to expand a node and a data source dialog pops up. Once you close the dialog box there is no option to open the dialog box again. You have to click on the minus sign to close the node and then click on the plus sign to expand it again. This triggers the dialog box to open again. After adding a data source to that node, this isn’t an issue because there will now be an item listed as the first item and clicking on it lets you add another data source.