Sunteți pe pagina 1din 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 weve created the project, and added a CRV and a DataSet. Its 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 Ill make use of only Page Header and Footer. Ill 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

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 rightclicking 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 can drag and drop the Print Date special field from Field Explorer -> Special Fields -> Print Date. Youll also notice that Ive 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

Footer Section Footer section is simple; just one special field and one LineObject. As youve 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. Youll 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

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 from DataTable starting with Title from Field Explorer inside the details section. As you drag and drop the fields inside the detail section, youll notice that the title of the field is also added to report designer. Since weve 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

Thats it. This is what we need for the design part. Now lets write some cool C# code to bring our report to life.

S-ar putea să vă placă și