Creating Graphical Reports With Crystal Reports in .NET - The Report
(Page 4 of 7 )
We will create our report using Visual Studio .NET and will save it in a .rpt file. The code above is actually redirecting the user towards the report page that will display the report.
Create a new web page called ViewReport.aspx. From the toolbox drag the Crystal Report Viewer control on the form and name it crViewer. Here is how it looks:
In the properties window you will find some properties like DisplayToolbar, EnableDrillDown, EnableViewState. These properties help us to customize our report; for this example we set them all as false. We also need to write some code to pass the arguments to our report like the ItemId, StartDate and EndDate, which we will do later. Save the form and close it. Before we go any further, we will create the report.
Creating the Report Right click on the solution name in the project explorer and click Add | Add New Item | CrystalReport. Name it ItemReport. Next we will be asked to select how our report is created. We will use the Report Expert, which is the default option. From the down options we can select the format of your report. Select "Standard" which is again the default. The next screen shows this:
We then have to select our data source. Select OLEDB (ADO) | Microsoft OLE DB Provider for SQL Server | Next. We need to provide the Server name, our UserId and Password, and the database to which we want to connect. After providing the information, click Finish.
Now you need to select the tables to which we will be displaying data. For our example, select "tblSales " only because all the data we need is from this table. Here is the screen.
Click Next to proceed. Now we have to add the fields to be displayed in the report. Select SaleDate and Amount. Click Next we will be offered the option to Group the information on the report using a Group By clause. We do not need this so just click Next again.
Next we have to select our chart type. There are a large number of different charts available. For our example, select Line and the first chart type and click Finish.
This is what you will see.
Right click on the Page Header area and click Insert | Chart. We will see a screen that we have already seen before. Click on the Data tab.
We mention here that we want only one chart in our report. Then we provide our SaleDate field under the On change of column. Note that we mention both the fields that we want to be displayed (SaleDate and Amount). Click on the Text tab and select a suitable Title for your report. Click Ok and we are almost done. We need to set the output parameters our code will query - so let's do that next.
Next: Creating Report Parameters >>
More C# Articles
More By Wrox Team