Aspdotnet-Suresh

aspdotnet-suresh offers C#.net articles and tutorials,csharp dot net,asp.net articles and tutorials,VB.NET Articles,Gridview articles,code examples of asp.net 2.0 /3.5,AJAX,SQL Server Articles,examples of .net technologies

Crystal reports example/sample in asp.net

Jan 18, 2012
Introduction:

In this article I will explain how to create crystal reports example in asp.net.


Description:

In Previous posts I explained
how to install crystal reports in visual studio 2010 and how to create rdlc reports using asp.net and pass parameters to rdlc reports using asp.net. Now I will explain how to create basic crystal reports using asp.net. Crystal Report is standard reporting tool for visual studio by using these we can display reports regarding employee details and display charts etc and crystal reports need minimal coding to display result. 

To implement crystal reports first design the table in database and give name UserInfomation

ColumnName
DataType
UserId
Int(set identity property=true)
UserName
varchar(50)
FirstName
Varchar(50)
LastName
varchar(50)
Location
varchar(50)

After completion of table creation enter some dummy data because we need to use that data to populate reports.

Now Open visual studio and create new website after that right click on your website and select Add new item in that select Crystal Report and click Add
 
After that add crystal report then it will prompt Crystal Report Gallery window in that select blank solution and click OK

A blank report will create in our application now click on CrystalReports menu under that select Database under that select Database Expert
 
After click on Database Expert now Database Expert wizard will open in that select Create New Section >> select OLE DB (ADO) >> in that click on + sign of OLE DB (ADO)

Now select Microsoft OLE DB Provider for SQL Server and click Next (Here we can select SQL Native client option also but sometimes during deployment if servers not contains this native client it will throw error).
 
Now enter SQL Server name, username, password and required database and click Next

After enter credentials for your required database click Next then click Finish (Here for my database I didn’t set any credentials for that reason I didn’t enter userid and password details don’t get confused).

After click Finish now our database loaded in OLEDB (ADO) section >> select your database >> select dbo >> select required tables

Now open tables in that select required table and move to selected tables section and click OK

After that Database Fields in Field Explorer populated with our required data table now drag and drop the required fields from data table to reports Details section

Now open your Default.aspx page drag and drop CrystalReportViewer control from Reporting tab.


Now select CrystalReportViewer and click on smart tag in right hand side and Choose new Report Source

Whenever we click on New report source one window will open in that select crystal report for Report Source from the available reports in dropdownlist and click OK.

After assign available report to CrystalReportViewer control check your code that would be like this

<%@ Register Assembly="CrystalDecisions.Web, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304" Namespace="CrystalDecisions.Web" TagPrefix="CR" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Crystal Report Sample</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<CR:CrystalReportViewer ID="CrystalReportViewer1" runat="server" AutoDataBind="True" ReportSourceID="CrystalReportSource1" />
<CR:CrystalReportSource ID="CrystalReportSource1" runat="server">
<Report FileName="CrystalReport.rpt">
</Report>
</CR:CrystalReportSource>
</div>
</form>
</body>
</html>
Now run your application your report will be like this

In case your report prompt window for UserName and password before we access data in that situation we need to set those details in code behind instead of assign crystal report to CrystalReportViewer control

Drag and drop CrystalReportViewer control click on right side smart tag of your CrystalReportViewer control and uncheck EnableDatabaseLogonPrompt

Our aspx code will be like this

<%@ Register Assembly="CrystalDecisions.Web, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304" Namespace="CrystalDecisions.Web" TagPrefix="CR" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Crystal Report Sample</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<CR:CrystalReportViewer ID="CrystalReportViewer1" runat="server" AutoDataBind="True" ReportSourceID="CrystalReportSource1" />
<CR:CrystalReportSource ID="CrystalReportSource1" runat="server">
<Report FileName="CrystalReport.rpt">
</Report>
</CR:CrystalReportSource>
</div>
</form>
</body>
</html>
Now Open your code behind file and set database connection settings and assign reports to the control before that first add following namespaces


using System;
using CrystalDecisions.CrystalReports.Engine;
After add namespaces write the following code in page load event

C# code


protected void Page_Load(object sender, EventArgs e)
{
ReportDocument reportdocument = new ReportDocument();
reportdocument.Load(Server.MapPath("CrystalReport.rpt"));
reportdocument.SetDatabaseLogon("username","password","SureshDasari","MySampleDB");
CrystalReportViewer1.ReportSource = reportdocument;
}
VB.NET Code


Imports CrystalDecisions.CrystalReports.Engine

Partial Class Default2
Inherits System.Web.UI.Page
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
Dim reportdocument As New ReportDocument()
reportdocument.Load(Server.MapPath("CrystalReport.rpt"))
reportdocument.SetDatabaseLogon("", "", "SureshDasari", "MySampleDB")
CrystalReportViewer1.ReportSource = reportdocument
End Sub
End Class
Now run your application and check your output that would be like this

 

If you enjoyed this post, please support the blog below. It's FREE!

Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email.

subscribe by rss Subscribe by RSS subscribe by email Subscribe by Email

100 comments :

Pratik said...

No Challenge to this site....This should be the template that every site must follow....

Anonymous said...

really its very useful

Rajendra Pundir said...

g8t example buddy its easy to understand thanks !

Paramita Roy said...

Helped a lot. Thanks

ganesh said...

Its a very good example of crystal report....
Is there a way to create a crystal report that can be used in any remote computer system.

Whenever I try to use my crystal report created in my local pc to remote pc having the same database name and feilds I have to recreate the entire crystal report

darshan said...

I have one doubts
my server name is
DARSHAN-PC\SQLEXPRESS
when i write this as a string i am getting error..please help me how to solve this problem
thanks

rajitha said...

very very very nice excellent

Unknown said...

how to send sms to mobile..

Anonymous said...

hi suresh from which college you had complited your BE

Dipak

Jay said...

sample project is very help full

thanks

Anonymous said...

wewewewqe

das said...
This comment has been removed by the author.
Amar Prasad said...

Thanks SURESH Ji..!!
Nice steps to geneate crystal report

JP.SIVARAJ said...

Hi,

This steps of creation is well also run in the browser during the execution in the editor having MS-Dev. kit IDE. But, after this page upload to IIS, the crystal report viewer could not load properly on client PC. Is there any possible setting in Web.Config .... Pls inform...

Thanks in advance...

JP.SIVARAJ

Anonymous said...

hai.. how can i add my crystal report to templates.. am using crystal report 10...can u help me....

Anonymous said...

thank you sir, it is good example
i have one query
enable databse login prompting
is it when i have SQL Security
not Windows Security
please reply my query
i mean
string server = @"\SQLEXPRESS";
reportdocument.SetDatabaseLogon("", "", server, "CrystalReport");
in this case i have window integrated security
so i don't have user name or password
thank you

Anonymous said...

if you have Windows Security then just remove
reportdocument.SetDatabaseLogon("", "", server, "CrystalReport");

hope it will work...

Anonymous said...

i want to ask Question
my crystal report working fine on local computer
when i uploaded it to server (not published version)
it is give me blank page
please replay me sir
this is my mail
devnet84@yahoo.com
thank you very much

yashwanth said...

It's very useful to me
Thank u very much

Unknown said...

Hi Suresh,

I am new to Crystal Reports,
can u please tell me how the Find button works in the report. If i type "a" and click on that find. it is not doing anything and displaying "End of Search". I have even added the OnSearch click event of that. But no use. Please help me.

Unknown said...

Hi suresh ,

this is one good example to create Report generations operation . thanks for your guidance.

Unknown said...

Hi Suresh,
I am new to crystal reports, we have a crystal report in that find button fuctionality is not working. Can you please help me. it is crystal 10.0.

DLR

Anu said...

HI I USED THE SAME PROCESS BUT UN ABLE TO MOVE TO THE NEXT PAGE AS WELL AS UNABLE TO EXPORT THE REPORT

Anu said...

hi suresh,
thank you your code helped me in parameter passing in crystal reports.
iam having a problem in crystal reports when iam passing the parameter i am un able to move to the next page as well as export.
iam using vs2010

rajen said...

I used the same code but am getting missing logon parameter error and when i enable log on prompt i get an input box to log on in database..... help me! my e-mail is
urban_hippy@hotmail.com

rajen said...

Hi Suresh....
The above error only appears when i move to the second page,the first page displays fine....

Anonymous said...

thanx for this hint..

amit said...

very easy to understand..

rifayee said...

hi suresh can u explain me how to display the selected record in a grid view and print the selected record in a crystal report...

Anonymous said...

I got more help in this your blog....Very fine...easy to understand...I give 1 vote to great site for IT developer....

Atul said...

I think @Suresh ur the best.....ur site is really bombastic......keep itup bro....

Unknown said...

I'm using a SAP Crystal Reports Web Viewer to display a CR report. It works perfectly fine in a CR Designer preview, however when I view it in a browser (any) the crosstab does not look as expected:

Anonymous said...

Can you tell me how to display images through crystal report in viewer. the images are stored in sql database

ayub said...

Hi Suresh this is good exampl but when i run the application to generate report using Crystelreport it is asking Sql Server Credientials ie Uid,Pwd everi time why ples help me

Unknown said...

hi sir how to add cssStyle in crystal repot. please help me

Anonymous said...

Thanks a lot.
Very simple to understand (Step by Step)

Anonymous said...

Could u pls provide code for how to add button to crystal reportViewer toolbar?

Unknown said...

thanks for step by step explanation

Ravi Jha said...

Hi,
Suppose we have ever growing database. Can we generate crystal report in real time by choosing some parameters like column names from the database?

thanks

Unknown said...

Hi Suresh... Went through your article,found it really useful.Need your help at the start up though.
---------------
When I add a new item (crystal report)to the website,I get a file to my solution explorer with an extension ( .mht ) though it shows a (.rpt) before adding it in the dialogbox where i can rename it and no such gallery to select the template shows.Am I missing out a plugin or something??..

Awaiting your valuable reply :D

Revathy said...

Hi Suresh,

Personally, This article very useful to me.I need a help,how to generate Payslip to more than one employee. Kindly give me some ideas like this article.

Thank u so much for your proper reply

thanks,
Revathy C

Anonymous said...

Hi sir,

This very good and i learn t from this and it is very useful to all like us. so keep it up


thanks.
UMESH KUMAR

Anonymous said...

Grt....Nice example...!
Good job...thanx..!!

Manas Jaiswal said...

thanx u so much...you give a very good example which is easy to use and understand.

Unknown said...

hi suresh..
I have a problem when uploading to the server, .. like this
BC30002: Type 'ReportDocument' is not defined.

Dim reportdocument As New ReportDocument()

Anonymous said...

Can we use Query to fetch data from multiple table.
If yes , than how?

beema said...

hi duresh garu i connected database is ado.net dataset but first page is displaying correctly when i ll click for next page it was asking logon failed incorrected parameteres.pls help me
advance thanks

abhilashblog said...

thanks for it. but not display report in web page please help me.

Anonymous said...

I need to how to create a xsd file with website and how to create a crystal report with xsd files

Anonymous said...

Nice Ji Thank U.

Abhishek Raj Narayan said...

great job ......thanks

Unknown said...

thank u this is very useful example....

Anonymous said...

Excellent example. So easy to follow. Thank you for this!

Unknown said...

quite helpful :)

now will you please solve my one problem ??
related to repeater ..

Anonymous said...

thanks for every think
this is very very useful

Unknown said...

Im getting error as database logon failed for Crystal Report im using vs2010 version 4.0.

Arun said...

ye site developers ke liye bhagwan hai

Unknown said...

Great Work... Its My dream Site

vijay said...

yes very good for learn but i want particular emp id with all details ..
how can write there code empid = 101
and given all information in report .


vijay

Anonymous said...

kya chutiyapa hai ye...

Anonymous said...

quite informative and good enough to work...

Anonymous said...

g8t example but after publishing it I am getting error :
WRN: Assembly binding logging is turned OFF.
how can i solve this issue pl help

Anonymous said...

Hello Suresh,

I have encounter a different issue during setting up crystal report for my windows application. I am using VS 2005 & Sql server 2005.Now i am not able to view any provider as u ave shown here
http://2.bp.blogspot.com/-Izb0Hxslebg/Txb8gZjST-I/AAAAAAAAA6E/jS82nd5X8G0/s1600/OledbProvider.png.

When i process like Database Expert > Create New Connection > OLEDB (ADO) a windows pops up but not provider s liseted there.Please let me what could be the issue, i have reinstalled OLEDB Provider(Downloaded form microsoft site) but of no use.I have Windows 7 32 bit is it something to do this OS.I have not even found MDAC for windows 7. Very much confused, please help me out on this, waiting for you revert.

Regards,
Manas

Anonymous said...

Hello Sir,
I have an asp.net application which is displaying the report using crystal report.The application is working properly on my local PC.I deployed this application on our dedicated server.But the following error occurring....
Retrieving the COM class factory for component with CLSID {5FF57840-5172-4482-9CA3-541C7878AE0F} failed due to the following error: 80070005...
could you pls give a reply..
Regards,
Janvi

Anonymous said...

hi,
How to increase bar height in crystal report.

Ravindra said...

really its nice buddy,

Anonymous said...

How can i displayed without probmpt of database details

Unknown said...
This comment has been removed by the author.
Anonymous said...

its nice but on image hover not working a zooming properly then what to need to do


AshProgHelp said...

Excellent ! Very Useful

Anonymous said...

how to make crystal report using vs 2012 and mysql server
i am unable to make crystal report
please help for this crystal report

Anonymous said...

hi.. sir,
i am unable to make Crystal Report using visual studio 2012 and mysql
please help for this code..
thank u..

Alok Kumar Rawat said...

sir,
crystal report local proper run but when i online this crystal report there are not running

Unknown said...

sir,
i have develop application in asp.net...with crystal report. It execute without any error in my pc where i developed it.
But, when i install dis application on another machine .crystal report shows error "System.MissingMethodException: Method not found: 'Void CrystalDecisions.Windows.Forms.CrystalReportViewer.set_ShowCopyButton(Boolean)'."
can u help me to solve this problem

Anonymous said...

great post helped a lot thankyou

Anonymous said...

Nice Suresh,You are doing wonderful job.
Thank a lot for this post.

Anonymous said...

Hi Friends,
Please help me to complete my task in project. I am new to make Crystal Report using VS 2005 C# with MySQL passing value through parameter. e.g. Bill_No and Acc_Year from multiple table(morethan 10 tables). Key values are Bill_No and Acc_Year. Thnaks and Advance wishes for your happy helping in this .... you can mail me the solution as soon as possible. e-mail:- nallas.murugan@gmail.com

neeraj said...

Sir, I followed all the steps in VS2010 and CR13 . Report is working fine on sever but on client Report is not visible any guidance

Deekshit said...

Hi Suresh, I have been a fan of your site since a year. you are providing a host of umpteen examples which i found useful to rev up my coding skills. thanks again.

Unknown said...

Hi Suresh how get crystal reports using store procedures with parameter, here i have to join three table and filter them according to Departments and Designation

thanks,
Shashi kiran

Unknown said...

Hii.. Can you tell me how to render text we have typed using ajax control toolkit editor(HTML text) just us how we have formatted in html editor on to crystal report?

Unknown said...

hi i want to disable all the tools and controls which is available in my report
because i don't want my (any) user to access (or) select any tools in my report except print....

Anonymous said...

i have a quizportal http://quizking.co.in/programming/Rdbms.aspx , but when i selects the option it takes time to fetch the status, i want minimize the time .how?plz view the site and answer me.

prashant rathore said...

can we bind crystal report dyanmically...????
reason is i olready made a website and do not want to alter oll code... is there any way to Bind crystal report , plz let me know... thank you sir

hari said...

only blank page is appearing. The crystal report is not loading. Any reason ? I followed the same steps as you did

hari said...

oops...I was using .NET 4.5 and it wasnt working.. Now I tried with .NET 2.0 and its working fine :) Thanks for your awesome tutorial ! :)

Unknown said...

i have query ... i want report like
1 sunil AAAAAAAAAAAA
BBBBBBBBBBBB
2 Suresh FFFFFFFFFFFFF
3 VISHAL LLLLLLLLLLLLLLL
KKKKKKKKKKK
UUUUUUUUUUU

Anonymous said...

Hello Suresh, I have a query that I followed above steps & created a crystal report but when I'm trying to run in browser screen shows nothing & report not showed on browser window. Why this occurs. Pleas help me with this. Thanks.

reyh said...

80007005 error what is this?

Anonymous said...

Hi friends,

Sub: Page is blank at run time
I am using complete this code but when i run my page, then page is blank. Please reply me with solution on ---- vbvipinbhayana88@gmail.com

Unknown said...

Hi friends,
i want to create crystal report in vs 2013 ultimate.How to i create this report. kindly help me for this.

Anonymous said...

I have a custom web application developed in VS2005 and integrated Crystal Reports XI. This application has been in production for 10 years. I just upgraded this application using VS2012 and Crystal Reports 13. When I try to view the report it shows correctly. Clicking on drill-down also shows the Drill Down report in another tab of the Report Viewer control. But clicking on next page while in the Drill-drown report, removes the drilldown report tab and take to the next page of the Main Report.

Any ideas/.

Thanks
Ridu

Unknown said...

thankss suresh

Unknown said...

Very Easy To UnderStand ..and Very Usefull Thank u So much.............

Vaishno Devi Yatra said...

Reallu nice piece. I want to know how to fetch data from mysql

WebApp@SoftwareEngineer916 said...

I use Crystal Report v13, SQL server 2012.
When I try to connect to a Database via ADO, I got the following error.

Login failed.
Details :ADO Error Code:0x80040e4d
Source:Microsoft OLE DB Provider for SQL Server
Description:Invalid authentication Specification
SQL State: 28000


Is there anyone how has this problem?
How can I fix this?

Thanks in advance,

Unknown said...

i am getting blank crystal report on IIS but on local working fine

Unknown said...

how to connect multiple crystal report rpt to one crystal report viewer.

Anonymous said...

Very Very useful and easily understandable solution. I am very grateful to you.
Following code will work for dynamic DB credential

//If rptTest is a Crystal Report file (rpt).
rptTest rpt = new rptTest();
rpt.DataSourceConnections[0].SetConnection("ServerName", "DBName", "DBUserId", "DBPassword");
rpt.SetParameterValue("@Parameter_Name", null);//Optional
crv.ReportSource = rpt;

arul said...

nice

Give your Valuable Comments

Note: Only a member of this blog may post a comment.

© 2015 Aspdotnet-Suresh.com. All Rights Reserved.
The content is copyrighted to Suresh Dasari and may not be reproduced on other websites without permission from the owner.