Crystal Reports Online Training

Learn Online, Anytime, Anywhere

Step-by-step online tutorials.

13.02 Implementing the 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 a database. As you can see, implementing the examples didn’t require any knowledge about data connectivity.

However, there are more 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, create a new report using the Report Expert, or select the menu options Crystal Reports > Database > Database Expert.

The Database Expert uses two dialog boxes: Data and Links. The Data dialog box, shown in Figure 13-1, is the way to add data sources to the report. It has two windows: Available Data Sources and Selected Tables.



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

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

Table 13-1. Available Data Sources

Data Source Description
ADO.NET DataSets 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.
.NET Object This is a list of all the classes in your .NET project. Note that since thjis is a comprehensive list for your project, most classes listed will not be acceptable as a Crystal Reports data source.
Current Connections Select from any connections already established within the Server Explorer.
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.
Access/Excel (DAO) Retrieve records using a DAO recordset that accesses a Microsoft Access database or Excel spreadsheet.
ADO.NET Connect to XML data or and ADO.NET dataset that doesn’t exist in your project.
Database Files Select a PC database file using its file location.
ODBC (RDO) Connect using an ODBC driver by selecting an existing System DSN.
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.

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.