Step 3: Add a DataSet to the project
Although, there are different ways you can
get the data to CRV, I'll show you here the DataSet technique. So, let's go
ahead and add a DataSet to the project. The following step is needed to have
the DataSet added to the project:
Select Add->New Item->DataSet from Solution Explorer. Change the name from DataSet1 to dsCDCatalog and click
the Add button. Please Cancel the TableAdapter Configuration wizard; we'll add
DataTable using the DataSet Designer.
Let's add the DataTable to our newly
created DataSet. DataTable is essential to load the reporting data; we'll use
the information from the DataSet/DataTable while designing the report. The
following step is required to have DataTable added to DataSet(dsCDCatalog):
Double-click on dsCDCatalog from Solution
Explorer; it'll open the designer view. Right-click the designer surface and
select Add->DataTable. Click the header and change the name to
dtCDCatalog (see the Figure 4).
Figure: 4 – Add DataTable to DataSet
Let's start adding columns to
DataTable(dtCDCatalog). Your designer screen should look like Figure 5.
Right-click on dtEmployee and select Add->Column to start
adding the columns to DataTable.
Figure: 5 – Add columns to DataTable
Repeat the action for the following
columns:
- Title (String)
- Artist (String)
- Country (String)
- Company (String)
- Price (Double)
- Year (String)
As you are adding the columns, by default
it is string data type. 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
Step 4: Add a Report to the project
So far we've created the project, and added
CRV and 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 OK button to complete the process to add report.
By default, you will see the 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
To add report to project is easy one, 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 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 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 can drag
and drop "Print Date" special field from Field Explorer->Special
Fields->Print Date. You'll also notice that I've change 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
Footer Section
Footer section is simple, just one special
field and one LineObject. As you've done with header section, you can
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.