![]() |
Database »
Database »
General
Intermediate
Develop Reports Using Crystal Reports in .NET 2005By Yunyou YaoA simple example which connects to an Oracle database to retrieve data with a DataSet, and then show a web report using CrystalReportViewer |
C#, Windows, .NET, Visual-Studio, DBA, Dev
|
|
Advanced Search Add to IE Search |
|
|
|
||||||||||||||||
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.
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.
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
<Employee Name="AAA" age="30" Sex="F" BirthDate="1/1/1960"></Employee>
<Employee Name="BBB" age="31" Sex="M" BirthDate="1/2/1960"></Employee>DataSet ds = new DataSet();
ds.ReadXml(Server.MapPath("App_Data/XMLFile.xml"));
ds.Tables[0].TableName = "DTEmployees";
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.
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.

Add fields, header, footer, etc for this report.
Drag a CrystalReportViewer CRVEmployees. In Page_load event, load report, and assign it to reportsource of CRVEmployees.
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();
Following is what the report looks like.

There are many ways to deploy web site containing crystal reports for .NET 2005. We only explore following way that works.
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;

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

If your Solution Explorer does not look like above, you will need to download CrystalReportsRedist2005_x86.msm [2]. 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�.

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

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).
Select Setup project DeploymentTest; From Build Menu, select Build DeploymentTest.
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.
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).
General
News
Question
Answer
Joke
Rant
Admin
Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads.
|
PermaLink |
Privacy |
Terms of Use
Last Updated: 19 Oct 2006 Editor: Chris Maunder |
Copyright 2006 by Yunyou Yao Everything else Copyright © CodeProject, 1999-2010 Web10 | Advertise on the Code Project |