Crystal reports

Overview

A simple report

Explains how to generate a simple report. So this should be the first place to start.

Customizing crystal report viewer

Explains how to customize crystal report viewer at design time. It also describes how to customize report viewer at run time.

Grouping the records

Explains how to group and summarize report data based on a report field.

Sorting

Describes how to sort data on a specified field. Also explains the various sort options.

Summarizing

Explains how to subtotal grouped data, add percentages to a report, and create running totals.

Filtering the records

Explains how to select and limit database records.

Using the parameters

Explains how to add parameters to your report so users can choose how they want the data to be filtered.

Creating sub-reports

Explains how to add hyperlinks to other reports or report data.

Using unbound fields

Explains how to use unbound fields to bind application data at runtime.

Exporting and printing

Explains how to export report data in different format and printing the report.

Creating a simple chart

Lists the charts available and explains how to insert charts into reports.

Please note:

  • This site is aimed to provide video samples to learn developing reports either using Crystal reports or SQL server reporting services.
  • At present only the video samples to develop basic reports are included. So it is most suitable for beginners. Video samples to learn advances concepts and solving real world problems will be added very soon.
  • Currently video samples shows generating reports using Visual Studio 2005. No other tools, plug-ins, project templates are used.

Summarizing

An aspect of a good report after filtering and sorting is summarizing. Summarizing creates totals, subtotals, average etc that help the viewer of the report understand the data better.

Steps:
  • Please refer A simple report to create a simple crystal report
  • Right click on the report. Insert > Summary.
  • In the Insert summary dialog, select the field to summarize from drop down.
  • Select summary option from the drop down next to it.
  • Click OK. Now designer will automatically add summary to footer section.
  • Click Main report preview button to view this report.
  • To customize the summary, select respective summery field in report. Right click on it and select Format object
  • Now select Common tab in Format editor dialog box.
  • Now click button next to display string label (at the bottom of dialog box).
  • Generate formula and click Save and close button
  • Again click Main report preview button to view the report.
Download video: Summarizing , Customizing summary

Creating sub-reports

A sub report is a report within a report. With sub reports, unrelated reports can be combined into a single report. You can coordinate data that could not otherwise be linked, or you can present different views of the same data in a single report.

Download video: Create a sub-report , Change parent link

Sorting

When you first add a database field to your report, the field's data values appear in the order in which they where originally entered into the database. By sorting records, you can organize data in a particular order to help you find and evaluate the information.

Steps:

  • Please refer A simple report to create a simple crystal report
  • Right click on the report. Report > Record sort expert...
  • In the Record sort expert dialog box, select any field.
  • Also select Sort direction.
  • Click OK
  • Click Main report preview button to view this report
Download video: Sorting records


Using the parameters

Parameters prompt the user of a report to enter information. Think of a parameter as a question that the user needs to answer before the report is generated. The information users enter, or the way they respond, determines what appears in the report. For example, in a report used by salespeople, there might be a parameter that asks the user to choose a region. The report would return the results for the specific region, instead of returning the results for all of the regions.

By using parameter fields in formulas, selection formulas, and in the report itself, you can create a single report that you can modify whenever your needs change. Parameter fields can also be used in sub reports.

Download video: Part 1 , Part 2

Grouping the records

In many reports you need to break the data into groups in order to make it easier to read and to analyze. This video describes how to group data based on a report filed.

Steps:

  • Please refer A simple report to create a simple crystal report
  • Right click on the report. Insert > Group.
  • Select from first combo Box, a field by which records are sorted.
  • To customize it, click Options tab Group dialog box. Now check Customize group name field. To customize using formula editor select Use a formula as group name and click button next to it.
  • Now generate formula in formula editor.
  • Click Save and close button in toolbar.
  • Click OK. Now designer will automatically create a new section and add new group into it.
  • Click Main report preview button to view this report
Download video: Grouping records

Using unbound fields

As name says, these fields are not associated any database fields. So they are used to define a custom field. Adding an unbound field to your report also enables you to programmatically pass fields from your application to the report.

Steps:

  • Please refer A simple report to add a new report to the project.
  • Expand unbound fields node in Fields Explorer.
  • Select String node and drag drop it into report.
  • Right click on the field and select Edit formula.
  • Now provide suitable formula in Formula Editor. Click Save and close
  • Click Main report preview button to view the report.
Download video: Unbound fields

Creating a simple chart

Parameters prompt the user of a report to enter information. Think of a parameter as a question that the user needs to answer before the report is generated. The information users enter, or the way they respond, determines what appears in the report. For example, in a report used by salespeople, there might be a parameter that asks the user to choose a region. The report would return the results for the specific region, instead of returning the results for all of the regions.

By using parameter fields in formulas, selection formulas, and in the report itself, you can create a single report that you can modify whenever your needs change. Parameter fields can also be used in sub reports.

Download video: A simple chart

Exporting and printing

The Crystal Report Engine allows you to deliver reports in many different ways. Using the export option, you can send the report to a disk file, to an Exchange folder, or to MS Mail (MAPI). The report can be exported to Excel, Crystal Reports, Microsoft Word, HTML, Portable Document Format (PDF), or Rich Text (RTF) format.

Steps:

  • Please refer A simple report to create a simple crystal report
  • CrystalReportViewer provides toolbar button to export report data in various formats.
  • Click Export Report. Select any format from drop down in Export Report dialog box. Navigate to required folder location in file system and save the file.

To export report through program:

Download video: Exporting report

Filtering the records

This video shows you how to filter the records you want included in a report. It describes how to filter data using record selection formulas. To filter data using parameters, please refer Using the parameters

Steps:

  • Please refer A simple report to create a simple crystal report
  • Right click on the report. Report > Select expert...
  • In the Choose Field dialog box, select a field by which to filter the data. Click OK
  • Select appropriate value from drop down in Select Expert dialog box. Set value from drop down next to it.
  • You can see the formula using Show formula button at the bottom of dialog box. Click Edit Formula to make any modification to the formula.
  • To add more filter criteria, click tab in the editor. Now follow the same step as done for first criteria.
  • Click OK.
  • Click Main report preview button to view this report.
Download video: Filtering records

Customizing crystal report viewer

Crystal Report Viewers work as a container of a report and allow us to view a crystal report in Windows and Web applications. Crystal Reports for Visual Studio .NET provides two report viewers - Windows Forms Viewer and Web Forms Viewer. As you can guess from these names, Windows Forms Viewer control is used to view reports in Windows Forms applications and Web Forms Viewer is used to display reports in Web Forms applications.

To view a report in the viewer, you simply need to set the ReportSource property of the control. The ReportSource property can be either a full name of the report file, a strongly typed report, or a ReportDocument object.

Using the CrystalReportViewer class members, we can customize the behavior of the viewer such as disabling or enabling viewer toolbar buttons, adding custom zoom factor, or moving to different views of the report at run time.

Steps to customize CrystalReportViewer using designer

  • Please refer "A simple report" to create a simple crystal report
  • Now open a windows form. Now open Toolbar > expand Crystal reports tab > select CrystalReportViewer > drag and drop it into windows form.
  • Open Properties of CrystalReportViewer object. Set following properties to customise the viewer.
    • ShowCloseButton
    • ShowExportButton
    • ShowGotoPageButton
    • ShowGroupTreeButton
    • ShowPrintButton
    • ShowRefreshButton
    • ShowTextSearchButton
    • ShowZoomButton
    • DisplayGroupTree
  • Now build and run the application.
Customizing CrystalReportViewer through program:

Download video: Customize viewer

A simple report

Crystal Reports has become a very versatile application for generating reports, particularly if you use Visual Studio. This video will guide you through generating a report using this tool. It is possible configure complete report using wizards. But I recommend you to avoid it.

Steps to create a simple report:

  • Click File > New project
  • Select Windows under visual C#
  • Select Windows application template
  • Right click on project in solution explorer. Select Add > New Item
  • Select Crystal reports in Add New Items dialog box. Name it and Click Add. Now visual studio automatically adds all required references and pops up a dialog Crystal reports gallery.
  • Retain default selection and click OK. Let us avoid using report creation wizard. So click Cancel button in Standard report creation wizard.
  • Now you are back into Visual studio designer with a blank report.
  • Now open Field Explorer. Right click on Database Fields and select Database Expert.
  • Please note Database Expert is same as Standard report creation wizard. I am using Microsoft Access database "Employee" for this sample. To create a new connection Expand Create New Connection > Access/Excel (DAO).
  • Click ... button in the dialog box. Now navigate to the Access file location and select it. Click Open.
  • Click OK in Access/Excel (DAO) dialog box.
  • Now observe the new connection created under Access/Excel (DAO) with tables listed under it.
  • Now click on any table node and press > to select a single table.
    • Hold Ctrl button, click on any table node and press > to select multiple table.
    • Press >> to select all tables.
  • Click OK. Now you are again back into Visual studio designer.
  • Expand Database Fields and also node listed under it.
  • Click on any field and drag it to details section of report.
  • Now open a windows form. Now open Toolbar > expand Crystal reports tab > select CrystalReportViewer > drag and drop it into windows form.
  • Open Properties of CrystalReportViewer object. Set ReportSource property to the crystal report we designed above.
  • Now build and run the application.
Download video: Part 1 and Part 2

Overview

Crystal Reports is a business intelligence application used to design and generate reports from a wide range of data sources. Several other applications, such as Microsoft Visual Studio, bundle an OEM version of Crystal Reports as a general purpose reporting tool.

Why Use a Reporting Tool?

It isn't difficult to retrieve data. You could write code to loop through record sets and print them in your Windows or Web application. In the .NET Framework, you could go further and bind that data to a control, such as a Repeater, DataList or DataGrid.

But to present this data in a formal report format is far more complex. Report features, such as consolidations, multiple level totals, charting, conditional formatting, and page-based output are difficult and time-consuming to program. Crystal Reports makes it easy to create and distribute complex reports.

Report Types

Crystal Report Designer can load reports that are included into the project as well as those that are independent of the project.

Strongly-typed Report:

When you add a report file into the project, it becomes a ‘strongly-typed’ report. In this case, you will have the advantage of directly creating an instance of the report object, which could reduce a few lines of code, and caching it to improve performance. The related .vb file, which is hidden, can be viewed using the editor’s ‘show all files’ icon in the Solution Explorer.

Un-Typed Report:

Those reports that are not included into the project are ‘un-typed’ reports. In this case, you will have to create an instance of the Crystal Report Engine’s 'ReportDocument' object and manually load the report into it.

Embedded report:

An embedded report is a report that has been imported into, or created within, a Visual Studio project. When a report is embedded into the project, a wrapper class is automatically generated for the report.

Non-embedded reports:

A non-embedded report is a report that is external to the Visual Studio project. You can use many ways to access the report and load it into an object model (to enable programmatic interaction with the report), but the report always remains external to the project.


Creating reports

Users install Crystal Reports on a computer and use it to select specific rows and columns from a table of compatible data. Users can then arrange the data on the report in the format needed. Once the report layout is complete it is saved as a file with the extension RPT. A report can be rerun anytime by reopening the RPT file and 'refreshing' the data. If the source data has been updated then the refreshed report will reflect those updates. The report can then be previewed on the screen, printed onto paper or exported to one of several different file formats such as PDF, Excel, text or CSV.

Report formats can vary from a simple column of values to layouts featuring pie charts, bar charts, cross-tab summary tables and nested subreports. Crystal Reports is designed for "presentation quality" reports so there are many options for enhanced formatting.

Fetching the data for the Crystal Report could be done by using any of the following methods:

Pull Model:

Where in Crystal Report handles the connection to the database using the specified driver and populates the report with the data, when requested.

Push Model:

Where it is the developer who has to write code to handle the connection and populate the dataset, and pass it on to the report. The performance can be optimized in this manner by using connection sharing and manually limiting the number of records that are passed on to the report.

What are cached reports?

Cached reports are report objects that have been stored in the ASP.NET Cache object, to increase performance and scalability. Crystal Reports supplies a specific framework for placing ReportDocument instances in the Cache. That framework automatically caches any report that implements the ICachedReport interface.


What is the ASP.NET Cache object?

In both ASP and ASP.NET, report objects are placed in Session or Application on the Web server, for two reasons:

1. 1. To persist the state of the report object across page reloads.

2. 2. To improve scalability and performance by placing large or slow-to-load reports into server memory.

In ASP.NET, an augmented variation of the Application object called Cache was introduced. Like Application, Cache still persists single instances of a report object, to be shared by all users. However, Cache adds intelligence that looks for file-based, key-based or time-based dependencies. These dependencies can automatically expire and even refresh report objects within the Cache, to keep the contents of the Cache current.


Running reports locally

The users who design the reports can run them as needed from within the report designer. When running reports directly within the report designer the user has the ability to change any feature of the report. The user can also create variations of the report by saving the modified RPT file under another name.

It is also possible to run a Crystal Report without using the full Crystal Reports designer software. These alternate methods for running reports include locally installed viewers, schedulers, and report distribution tools. These are typically third-party software programs (independent of Business Objects) that allow you to open, refresh, preview, print and export an RPT file. In 2007 Business Objects released their own viewer, Crystal Reports Viewer XI, but unlike the independent viewers it does not allow the user to refresh the report, but only to view static data saved in the RPT file.

Some of the independent viewers add other capabilities such as allowing the user to schedule a report to run automatically at certain times. Still others allow reports to be burst and/or distributed via Email.

Crystal reports is bundled with a set of ActiveX controls that, when embedded in a simple GUI, can provide an alternative user interface. These same controls allow reports to be deconstructed into their base objects. This, in turn, allows the same reports to be generated at run time, customizing them as necessary.