|
|
Creating Crystal Report in ASP.NET
RRaveen
Published Date: 4/18/2009 10:08:19 AM
Views: 37417
Abstract:
Reporting plays an important role in many information systems. Crystal report supports ASP.NET to design a report and render in ASP.NET page with records.
Introduction:
The purpose of this tutorial is to explore how to create crystal report in ASP.NET applications. Crystal report supports web Application reporting. Therefore ASP.NET has a feature to develop reporting with crystal reports.
Prerequisites:
1. SQL Server 2005 2. Visual studio 2005/2008 3. Crystal report
Before starting to design a report, you need a database which is going to be used by the report. Here I have designed a small database for this demonstration.

The created database name is “HouseRental” with “HouseOwnerInfo” table. There are eight columns in the “HouseOwnerInfo.
Let us design a report for this table, get owners summary report which will be used to pass date parameter to process the report.
Note: The database design is only for demonstration purpose.
Let us start designing the report. For that, there are two standard ways. The first way is we can use the crystal report and second one is we can use the Visual studio.
First open Visual studio 2008 or 2005 and create new web project called “CrystalReportInASPNET”. Then right click the project and select Add New Item from the menu.
Select Crystal Report from the templates list window. When you select crystal report, give a meaningful name to the report. Here I have given “SampleRpt.rpt”. Then click Add button.
After you click the Add button, you will get a welcome window as shown by the following figure.

Keep the Standard report format and click OK button. Then you need to create the database connection to access tables within the database. Once you click OK button, system gives a window to select the connection type as shown below.

This demonstration report is to work with SQL Server 2005 database. So you need to select SQL native client as provider (As above figure shows).
Then click Next button, to continue report creation process. Then you need to assign details of SQL Server and user credential to access the database from the report. Then you need to expand current connection tag, select your database connection then select the relevant table as shown by the following figure.
 Then click Next button to continue. There you need to select fields from selected tables to design report as shown by the following figure.
 Then click Next button. Now you have done necessary effort and finished the final step. As a result, you will get report like this.

Now you need to add crystal report viewer on the ASP.NET Webpage.
Let us see, how we can add the report viewer on the page, just look at these html tags.
Create a table in form object. Then add a HTML row and a column. Then place the crystalReportViewer to the column as shown above HTML tag. If we compile this application, it will give a compiler error “CR doesn’t exist”.
Therefore, you need to register crystal report namespace on the top of the page as shown below.
Note: when you double click on toolbox in the crystalreportviewer Visual studio will do all registration and etc.
Now write few lines to display report on the viewer.
Here we have to write code under the OnPreRender event,I hope you know about ASP.Net event life cycle. Please visit the following links for more information.
1. http://msdn.microsoft.com/en-us/library/ms178472.aspx 2. http://msdn.microsoft.com/en-us/library/ms178473.aspx
The reason for using “PreRender” event is this is the most suitable event for value setting in asp.net, Otherwise we can set in “PageLoad” event too. Here I did not use a button to load report on the viewer, therefore I have used “PreRender” event. On my code just create a report document object and load report from the path. Here we used the Server. MapPath() method to get absolute path from the report file name. Then build the web application and run, you will get result like follow.
 Result seems cool right!
Note: When you are trying to deploy in your live server, you may face one problem. That is database login fail to report. To ignore that, best approach is creating dataset schema to your tables, then attach the dataset to report. I hope to discuss this scenario on my next article. Keep your eyes on the www.highoncoding.com.
Conclusion: This article discussed about creates report with ASP.NET, and how to setup the CrystalReportViewer on the ASP.NET page.
Author: My
name is RRaveen, currently living and working in Singapore. Ii am
highly focusing on to provide better Solutions to business problems
which are commonly an organization facing,
retrieve information on time using information technologies.Since i
loves windows mobile technology design and implementation business
applications which is based on C#.And my other specializations are
Asp.net,WPF and WCF . i have been working on many back ends which
are Mysql,Sqlserver and Oracle/PL/SQL/TOAD hands on experience more
than 3 and a half year.
References: 1. http://www.sap.com/solutions/sapbusinessobjects/sme/reporting/crystalreports/index.epx 2. http://www.highoncoding.com/Articles/201_Creating_Crystal_Reports_Using_Typed_DataSet.aspx
Comments/Feedbacks
|
|
|
|
Subject: parameters and input box's
Name: billy
Date: 4/29/2009 1:15:46 AM
Comment: Excellent!
Do you have any examples with input box's being passed as parameters to reports. |
|
|
|
|
|
Subject: Close report
Name: Ladislav
Date: 4/29/2009 5:48:05 AM
Comment: Make sure that you add Page_Unload event handler to your code and call report.Close() and report.Dispose() method of ReportDocument. Otherwise you'll find yourself in trouble because there is a limit of how many Crystal Reports can be loaded and open at once - it is around 70. It can be changed in registry. If you reach this limit, no other crystal report will be loaded and you will get an error until you restart your server. So make sure that you manually Close and Dispose of every report you load. |
|
|
|
|
|
Subject: It's great!
Name: Renato Gil
Date: 4/29/2009 5:57:13 AM
Comment: Thank you! |
|
|
|
|
|
Subject: Good Article Approach
Name: Thanigainathan
Date: 4/29/2009 8:56:30 AM
Comment: Hi,
Your Article is very nice. One small doubt ? Is there any licence needed to deploy this in live server's.
Thanks,
Thanigainathan.S |
|
|
|
|
|
Subject: About Crystle Report
Name: kirti
Date: 4/29/2009 9:59:53 PM
Comment: This crystle report fine with local server when uploaded on live server it give error for Crystle Report Assebaly not Register on server how it manage please help me |
|
|
|
|
|
Subject: License
Name: Sam
Date: 4/30/2009 7:12:09 AM
Comment: Is there any Crystal licenses (server or client) to buy before utilizing crystal reports in asp.net? Or having a professional license for VS is enough? |
|
|
|
|
|
Subject: ASP.NeT2 criystal riport
Name: mohhamad
Date: 5/12/2009 3:48:13 AM
Comment: Thank you! |
|
|
|
|
|
Subject: failed to load report
Name: Anoop
Date: 5/20/2009 12:20:10 AM
Comment: is there any solution for removing this error without restarting server |
|
|
|
|
|
Subject: Crystal report
Name: Ali
Date: 2/9/2010 6:15:27 AM
Comment: nice artical thanks...
can you send some basic ideas about WPF , WCF and design patterns in asp.net |
|
|
|
|
|
Subject: Crystal Reports
Name: Madhu
Date: 4/3/2010 4:04:49 AM
Comment: can we add fields in vertical format(in crystal reports)? |
|
|
|
|
|
Subject: Computer Science
Name: Arun. P.S
Date: 4/30/2010 11:37:36 PM
Comment: Your articles should improve a lot......... |
|
|
|
|
|
Subject: Reporting sottwares on reportipedia
Name: William Devore
Date: 5/18/2010 9:28:56 PM
Comment: Usually i used crystal reports to output the queries result from my database program. We can say it is the front line of our developed program because user interacts with this reports. This reporting process should actually be simple, user should be allowed to design and customize the reports format easily.
But in contrary, it seems that this process is so overwhelming especially at the enterprise level. Every software companies claim that they have made "easy-to-use" reporting software, but unfortunately this is just a gimmick, none of them are. Most of them are just another brothers and sisters of crystal reports, plain and complicated reporting output.
It may be hard to find such a user friendly reporting softwares, but a great place to start is http://www.reportipedia.com - it's a wiki with information on all the major reporting packages. Hope you find it useful, happy to share with you... |
|
|
|
|
|
Subject: Feedback
Name: Vikas Pandey
Date: 6/18/2010 6:36:23 AM
Comment: The way of presentation is nice. |
|
|
|
|
|
Subject: Require clear information
Name: Jayasudha K
Date: 8/10/2010 11:29:26 PM
Comment: while I am entering my userid and password its not taking... |
|
|
|
|
|
Subject: Code for passing parameters or formula feilds
Name: Gangadhar Nalla
Date: 8/29/2010 12:52:23 AM
Comment: Dear Sir,
i, have a Cr2008 report with 3 formula fields or parameters, like 2 dates and one dropdown list, i, need a complete code in vb.net as codebehind, how to call and how to pass the parameters or formula fields and query to the report.
Kindly send me a code as soon as possible .
Thanks in Advance
Warm Regards
Gangadhar Nalla
|
|
|
|