Crystal Reports
Essay by review • December 1, 2010 • Essay • 1,038 Words (5 Pages) • 1,501 Views
There have been many enquiries about Crystal Reports on the site and unfortunately there are not too many technical articles and source code samples available on Crystal Reports on C# Corner or any where else. As usual, I decided to dedicate some time to Crystal Reports and fill the Crystal Reports section of C# Corner and VB.NET Heaven sites. As a result, in next couple of weeks you will see some Crystal Reports articles from me. Hopefully, you will enjoy these articles. Again, I encourage you to share your knowledge with other developers to make our lives easier.
Unlike previous versions of Visual Studio, Crystal Reports is an integral part of Visual Studio .NET and ships as a part of it. By making Crystal Reports a part of Visual Studio .NET suite, Microsoft has added one more useful tool to the Visual Studio family. In this article, I will show you how to create a simple report using Crystal Reports and Visual Studio .NET. In my following article, I shall dig more into Crystal Reports .NET.
To follow this article, first create a Windows application by selecting File->New->Project->Visual C# Projects->Windows Application template from Visual Studio .NET project templates. I give my project name IntroToCR.
Adding a Report to a Project
Crystal Report is a part of Add New Item templates available in Visual Studio. To add a report to the project, add a new item by Right Clicking on the project in Solution Explorer and selecting Add->Add New Item->Crystal Report as you can see in Figure 1. I change the name of the report to Customers because we will be displaying customers related information from Northwind database.
Now click the Open button.
Figure 1. Adding a Report to the Project
The next step is to select the report document type from Crystal Report Gallery. As you can see from Figure 2, Crystal Report Gallery provides three options Using the Report Expert, As a Blank Report, or From an Existing Report.
For our first application, lets keep all options as default. I will be discussing rest of the options in my following articles.
Figure 2. Selecting a report type.
By clicking the OK button adds Customers.rpt file to the project and launches Standard Report Expert wizard as you can see in Figure 3, where you can select a data source. The Standard Report Expert wizard has 8 different tabs. I will discuss these tabs in more details in my following articles. The main purpose of this article is to show you how to create your first report in a few simple and quick steps.
Figure 3. Standard Report Expert wizard
Adding a Data Source
Now our next step is to link a data source to the wizard. There are different ways to link a data source to the wizard. The simplest way is to click on the OLE DB(ADO) tree item in Figure 3.
Clicking on OLE DB(ADO) item launches OLE DB Provider dialog where you can select a data source as you can see in Figure 4.
Figure 4. OLE DB Provider dialog
Now on the OLE DB Provider, you can select a provider. I select Microsoft OLE DB Provider for SQL Server. If you do not have access to SQL Server, you can select Access or other data providers.
After select Microsoft OLD DB Provider for SQL Server, you will see the Next button is activated on the wizard.
The Next button allows you to provide the connection information about a data source. As you can see in Figure 5, we select Northwind database.
Figure 5. Connection Information dialog
Now you can click the Finish button.
This option adds the Northwind database to the list and if you expand the database item, you will see the database tables.
Now on this page, I select Customers table and add it by clicking Insert Table button. Now you can see the table listed in the right list box. See Figure 6.
Figure 6. Northwind database tables
Now
...
...