Add Reporting to Your ASP.NET Site

By Leidago Noabeb


[next]

Though reporting is not often used on websites, it is slowly becoming important -- especially in intranet environments. ASP.NET comes with Crystal Reports, a tool you can use to create reports for a website. This article walks through the creation of ASP.NET reports using a database, Visual Studio 2008 and Crystal Reports.

Here's the SQL for the database we will use:

Just run this SQL and you should have a fully functioning database in no time. The database has two tables, one that holds user information and another that holds CD information. The two tables are linked by the userID, meaning that you will be able to generate the following reports:

  • Number of CD's by user
  • Number of users
  • Number of CD's

There are essentially two ways of creating a report: the manual way and the automated way. Let's start with the automated approach. Open up your website in Visual Studio 2008 and add a new item. A new Items dialog should popup. Select Crystal Reports and then enter "CDrep" as the name of our report:

Figure 1: Adding a New Report

When you click OK, another dialog will popup:

Figure 2: New Report Dialog Box

On this dialog box, select Using Report Wizard and make sure that your Expert is Standard. Click OK. A new dialog box that looks like this will appear:

Figure 3: Second New Report Dialog Box

Click on New Connections and then select the OleDB connection. When you have done this the next dialog will appear.

Figure 4: Third New Report Dialog Box

On the list that appears, select SQL Native Version 10.0. This is because we are using SQL Server 2008. If you are using another database system, select the appropriate provider. The next screen will require you to add your server name, username and password information. Enter the information as appropriate. The wizard will take you through a number of steps.

Figure 5: Report Creation Wizard -- Data Sources

Figure 6: Report Creation Wizard -- Fields

Then it will generate a report layout that looks like this:

Figure 7: First Report Layout

Click on the preview button and you should be able to see a preview of what your report will look like. On the left of the screen you should see a number of items that you can use to customize your report. Let's add a header to it. Go to the toolbox, select a text object and place it to the right of the date. Add any text you want to it. I've added "Creating a Report for Website". Your report should look like this:

Figure 8: Report for a Website


[next]