Click here to Skip to main content
15,881,882 members
Articles / Programming Languages / C#

Develop Reports Using Crystal Reports in .NET 2005

Rate me:
Please Sign up or sign in to vote.
3.88/5 (18 votes)
19 Oct 2006CPOL4 min read 251K   2.9K   90   15
A simple example which connects to an Oracle database to retrieve data with a DataSet, and then show a web report using CrystalReportViewer

Introduction

When we developed web applications using .NET 2005 with an Oracle database there was a request from our customers. They wanted us to print reports with header and footer on each page, and convert the file to other file formats such as Excel. The requirement can be implemented using Crystal Reports in .NET 2005. This article is a note for us on how to develop reports using crystal reports in .NET 2005 with Oracle, and to deploy web site with crystal reports which took us much time, especially for deployment. Hopefully it can help you, and save you some time.

Develop Reports Using Crystal Reports in .NET 2005

Using Crystal Reports in Visual Studio .NET 2005 you can create very complex reports. We just give a simple case which connects to an Oracle database to retrieve data with a DataSet, and then show a web report using CrystalReportViewer.

1. Retrieve data to DataSet from a data source  

C#
OracleAccess oa = new OracleAccess(login, pwd, database);
DataSet ds = oa.Get_Data(id));
ds.Tables[0].TableName = "DTPrint"

For convenience in a demo, our code reads data to a dataset from an XML file: XMLFile.xml

XML
<Employee Name="AAA" age="30" Sex="F" BirthDate="1/1/1960"></Employee>
<Employee Name="BBB" age="31" Sex="M" BirthDate="1/2/1960"></Employee>
C#
DataSet ds = new DataSet();
ds.ReadXml(Server.MapPath("App_Data/XMLFile.xml"));
ds.Tables[0].TableName = "DTEmployees"

2. Create DataSet DSEmployees.xsd for Available Data Sources

In the App_code directory, add DataSet DSEmployees.xsd. Crystal Reports will find this data source. Then add DataTable DTEmployees, and its columns (Name, Age, Sex, and BirthDate) in the DataSet.

3. Create Cristal Report: CREmployees.rpt

Add New Items | CrystalReport | Using the Report Wizard. In the window of Standard Report Creation Wizard, you can find the table DTEmployees from Project Data | ADO.NET DataSets | DSEmployees in Available Data Sources. Select this available data source DTEmployees.

Image 1

4. Edit your crystal report

Add fields, header, footer, etc for this report.

5. Create a web page CRPage.aspx

Drag a CrystalReportViewer CRVEmployees. In Page_load event, load report, and assign it to reportsource of CRVEmployees.

C#
ReportDocument rd;
DataSet ds = new DataSet();
ds.ReadXml(Server.MapPath("App_Data/XMLFile.xml"));
ds.Tables[0].TableName = "DTEmployees";
rd = new ReportDocument();
rd.Load(Server.MapPath("CREmployees.rpt"));
rd.SetDataSource(ds);
CRVEmployees.ReportSource = rd;
CRVEmployees.DataBind(); 

6. View in Browser for CRPage.aspx

Following is what the report looks like.

Image 2

Deploy Web Site Containing Crystal Reports for .NET 2005

There are many ways to deploy web site containing crystal reports for .NET 2005. We only explore following way that works.

1. Create a Web Setup Project for Deployment

On File menu, New | Project; In New Project window, select Other Project Types | Setup and Deployment, select Web Setup Project; Input project Name, location, and select Solution to Add to Solution;

Image 3

2. Add Merge Module

In Solution Explorer, Right Click Project DeploymentTest, and select Add | Merge Module; Select CrystalReportsRedist2005_x86.msm;

Solution Explorer should look like:

Image 4

If your Solution Explorer does not look like above, you will need to download CrystalReportsRedist2005_x86.msm. Then copy it to the folder \Program Files\Common Files\Merge Modules. If microsoft_vc80_atl_x86.msm and policy_8_0_microsoft_vc80_atl_x86.msm aren’t there, you also need download and copy them. If they are still not in Detected Dependencies after adding merge module CrystalReportsRedist2005_x86.msm, you may need to uninstall your Visual Studio 2005. When reinstalling it, check boxes “Itanium Compilers and Tools” and “X64 Compilers and Tools”. [2]

 

Image 5

 

3. Add output files to the web setup project

In Solution Explorer, right click setup project DeploymentTest, Add | Project Output…; Select Content Files, leave Configuration to Active;

Image 6

Click OK; Double Click item Content Files from … (Active) in Solution Explorer; In Properties window, set DefaultDocument as the start page for your web site (CRPage.aspx); VirtualDirectory property is set to the project name (DeploymentTest).

4. Build Web Setup Project

Select Setup project DeploymentTest; From Build Menu, select Build DeploymentTest.

5. Deploy Web Setup Project

Outside Visual Studio, go to your setup project directory, copy your setup project fold (DeploymentTest) to your remote web server; On your web server, double click your setup project DeploymentTest.msi to deploy your web site.

Go through all the steps which will deploy to your default web site C:\Inetpub\wwwroot\ DeploymentTest.

6. Create a virtual directory for web project

In your IIS Application Server Management console, create a virtual directory, which refer Content directory path to C:\Inetpub\wwwroot\ DeploymentTest; You also should check IIS server for ASP.NET version, Application pool. Also You should setup Documents | default content page to your start page (CRPage.aspx).

References

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
United States United States
Yunyou Yao is a Senior IT Specialist in Houston, USA.

Comments and Discussions

 
GeneralMy question Pin
BalasubramanianK6-Mar-09 1:38
BalasubramanianK6-Mar-09 1:38 
Questionfree download CrystalReportsRedist2005_x86.msm Pin
Member 366830813-Dec-08 19:37
Member 366830813-Dec-08 19:37 
AnswerRe: free download CrystalReportsRedist2005_x86.msm Pin
annuradha30-Apr-09 23:41
annuradha30-Apr-09 23:41 
GeneralRe: free download CrystalReportsRedist2005_x86.msm Pin
amtadhani27-May-09 11:57
amtadhani27-May-09 11:57 
GeneralCrystalReportsRedist2005_x86.msm Size Pin
Anubhava Dimri14-Jun-08 2:17
Anubhava Dimri14-Jun-08 2:17 
GeneralPlease help me in Crystal Reports Pin
jkchoudhary31-Oct-07 21:42
jkchoudhary31-Oct-07 21:42 
GeneralRe: Please help me in Crystal Reports Pin
Yunyou Yao1-Nov-07 4:25
Yunyou Yao1-Nov-07 4:25 
Generalwebsetup notworking with ms access Pin
haja me3-Oct-07 23:53
haja me3-Oct-07 23:53 
Generalcrystal report c#.net windows application 2005 Pin
Bala_843-Oct-07 2:34
Bala_843-Oct-07 2:34 
Questionhow to deploy on remote server Pin
Jfergus6-Jul-07 5:43
Jfergus6-Jul-07 5:43 
QuestionFANFREAKINGTASTIC! Pin
dfowler196528-Apr-07 5:25
dfowler196528-Apr-07 5:25 
QuestionUsing Collections instead of DataSet Pin
Jawad Munir26-Feb-07 20:05
Jawad Munir26-Feb-07 20:05 
Hi!
I want to use custom business entities from a separate project containing classes (business classes) that implements ICollection Interface. Is it possible to use them for data retrieval instead of using dataset that is comparatively heavier and generates performance issues.

Regards,
Jawad Munir
GeneralChanging type of database at run time Pin
AlexEvans28-Nov-06 16:02
AlexEvans28-Nov-06 16:02 
Questionquestion Pin
marc l host26-Oct-06 5:44
marc l host26-Oct-06 5:44 
AnswerRe: question Pin
Yunyou Yao8-Nov-06 3:56
Yunyou Yao8-Nov-06 3:56 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.