crystal report with dataset

5
As you are adding the columns, the default data type is string. Go to the Properties windows after selecting a column to change it from string to Int32. After you are done with adding columns, it should look similar to Figure 6. Figure 6: DataTable after adding needed columns So far we’ve created the project, and added a CRV and a DataSet. It’s time to work on the report. Following are the steps required to add Report (rptXMLData.rpt ): Select Add -> New Item -> Crystal Report from Solution Explorer. Change the name from CrystalReport1.rpt to rptXMLData.rpt and click the Add button to complete the action. A dialog box of Crystal Reports Gallery will appear. Select “As a Blank Report” option and click the OK button to complete the process to add report. By default, you will see that rptXMLData.rpt is open for you in designer mode and its default setting. For this example I’ll make use of only Page Header and Footer. I’ll reduce the height of Report Header and Footer. Typically, after all this your report designer should look similar to Figure 7. Figure 7: Newly added report in design mode

Upload: linustorl

Post on 02-Apr-2018

245 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Crystal Report With Dataset

7/27/2019 Crystal Report With Dataset

http://slidepdf.com/reader/full/crystal-report-with-dataset 1/5

Page 2: Crystal Report With Dataset

7/27/2019 Crystal Report With Dataset

http://slidepdf.com/reader/full/crystal-report-with-dataset 2/5

 

Adding a report to the project is easy. The challenge is to fill in the empty report layout. Whether

this is your first report or you are a reporting junkie like me; we must deal with the most basic

building blocks of the report writing. That is, the header, the detail, and the footer.

Typically, reports are designed with specific page size and layout in mind. Our report is Letter

size and Portrait layout. You can explore various properties attached to the report layout by right-clicking anywhere on the open designer surface (gray area) and selecting Report and Design

Properties.

It is always advisable to draw a prototype of your report on paper before you start the design

process. As you can see in Figure 1, we have the report name and report date in the header

section. The body section has the employee list information; the footer carries the page numbers.

Header Section 

Our header section is consists of five Text Object, two Line Object and one Special Field.

Please drag and drop Text Object and Line Object from Toolbox -> Crystal Reports. You candrag and drop the “Print Date” special field from Field Explorer -> Special Fields -> Print Date.

You’ll also notice that I’ve changed the color and font after placing the report object on the

designer surface. Please make sure your header looks similar to Figure 8.

Figure 8: Report Header and Footer

Page 3: Crystal Report With Dataset

7/27/2019 Crystal Report With Dataset

http://slidepdf.com/reader/full/crystal-report-with-dataset 3/5

 

Footer Section 

Footer section is simple; just one special field and one LineObject. As you’ve done with the

header section, you can drag and drop a LineObject from Toolbox -> Crystal Reports.

Similarly, you can drag and drop “Page N of M” special field from Field Explorer -> Special

Fields -> Page N of M. Please see Figure 8 and make sure the Footer look similar.

Detail Section 

The Details section of the report will have the CD Catalog list details. Now the question is: From

where will we get the data? Well, as you know, at the beginning we added a DataSet to this

project. We will use this DataSet as the source of data for our report.

Adding a DataSet as source of data for a report is easy. You’ll start with Right-Clicking on any

open area on Report Designer -> Database -> Database Expert… As a result of this action, the

Database Expert dialog box will appear. You can click on Project Data and expand the node

ADO.NET DataSet. Please select the dtCDCatalog DataTable from our DataSet and click on

“>” button to move it to selected tables section on right-hand side (Please see Figure 9).

Figure 9: Adding DataSet as report data source

Page 4: Crystal Report With Dataset

7/27/2019 Crystal Report With Dataset

http://slidepdf.com/reader/full/crystal-report-with-dataset 4/5

 

Once the report source is specified, all we have to do is drag and drop the fields from DataTable 

inside Detail section on report designer surface. You can drag and drop all the fields fromDataTable starting with “Title” from Field Explorer inside the details section.

As you drag and drop the fields inside the detail section, you’ll notice that the title of the field is

also added to report designer. Since we’ve already taken care of field header, just delete the

default added field header. Please make sure the final report designer layout looks similar to

Figure 10.

Figure 10: Final report design layout

Page 5: Crystal Report With Dataset

7/27/2019 Crystal Report With Dataset

http://slidepdf.com/reader/full/crystal-report-with-dataset 5/5

 

That’s it. This is what we need for the design part. Now let’s write some cool C# code to bring

our report to life.