Crystal Report With DataSet and DataTable Using C# - CodeProject

8
05/12/11 Cr\stal Report Zith DataSet and DataTable using C# - CodeProject 1/8 ZZZ.codeproject.com/KB/cs/Cr\stalReportNDataTable.asp[ 8,305,908 members and growing! (39,103 online) Email Password SigQ iQ JRiQ Remember me? Lost password? Home Articles Quick Answers Discussions Learning Zones Features Help! The Lounge SeaUch 12 Article Browse Code Stats Revisions Sponsored Links ª Languages ª C# ª Reporting Licence CPOL First Posted 28 Aug 2008 Views 81,951 Downloads 1,917 Bookmarked 58 times Cr\stal Report with DataSet and DataTable using C# By Rehan Ahmad Abbasi | 8 Sep 2008 .NET1.0 .NET1.1 .NET2.0 Win2K WinXP Win2003 Vista .NET3.0 .NET3.5 C# , + Crystal Report with Dataset and DataTable using C# Part of The SQL Zone sponsored by See Also More like this More by this author 3.78 (30 votes) Download source - 86.83 KB Introduction In my previous article, I described how to create Crystal Report with Oracle Views. In this article, I am going to demonstrate how to create a Crystal Report with ADO.NET DaWaTable . You will find this article very interesting, simple and easy to understand. This article needs basic knowledge of .NET. Note: Please vote for this article. Background No background knowledge is needed for this article. This article is very simple and just requires very basic knowledge of .NET. But I recommend reading my previous article as well, though it has no direct relation with this article. Using the Code Now enough of theory, we will move to our point. So here we go... I have created 2 sample tables for this project. Scripts of tables are as follows, with some sample insert query to have sample data. Collapse | Copy Code creaWe Wable Wbl_projecW ( PROJECT_ID NUMBER( 4 ), PROJECT_NAME VARCHAR2( 150 ), GROUP_CODE NUMBER( 2 ) ) creaWe Wable Wbl_projecW_groXp ( MX-Frame Business Application Framework www.mxframe.net Search for ASP.NET Add search engine functionality to your ASP.NET web site. Features... keyoti.com See Also... Creating animations with Dundas Chart for ASP.NET Smarter Data Labels with Dundas Chart SmartLabels Understanding Chart Areas with Dundas Chart for .NET Making Sense of Geographic Data with Dundas Map and AJAX DestroyWindow in VBScript SmartLink Create data-driven applications

Transcript of Crystal Report With DataSet and DataTable Using C# - CodeProject

Page 1: Crystal Report With DataSet and DataTable Using C# - CodeProject

05/12/11 Crystal Report with DataSet and DataTable using C# - CodeProject

1/8www.codeproject.com/KB/cs/CrystalReportNDataTable.aspx

8,305,908 members and growing! (39,103 online)Email Password Sign in Join Remember me? Lost password?

Home Articles Quick Answers Discussions Learning Zones Features Help! The Lounge Search

12Article Browse Code Stats Revisions Sponsored Links

» Languages » C# » Reporting

Licence CPOL

First Posted 28 Aug 2008

Views 81,951

Downloads 1,917

Bookmarked 58 times

Crystal Report with DataSet andDataTable using C#By Rehan Ahmad Abbasi | 8 Sep 2008

.NET1.0 .NET1.1 .NET2.0 Win2K WinXP Win2003 Vista .NET3.0 .NET3.5 C# , +

Crystal Report with Dataset and DataTable using C#

Part of The SQL Zone sponsored

by

See Also

More like this

More by this author

3.78 (30 votes)

Download source - 86.83 KB

Introduction

In my previous article, I described how to create Crystal Report with Oracle Views. In this article, I am going to demonstrate how to create a Crystal Report with ADO.NET D a t a T a b l e .

You will find this article very interesting, simple and easy to understand. This article needs basic knowledge of .NET.

Note: Please vote for this article.

Background

No background knowledge is needed for this article. This article is very simple and just requires verybasic knowledge of .NET. But I recommend reading my previous article as well, though it has no direct relation with this article.

Using the Code

Now enough of theory, we will move to our point. So here we go... I have created 2 sample tables for this project. Scripts of tables are as follows, with some sample insert query to have sample data.

Collapse | Copy Code

c r e a t e t a b l e t b l _ p r o j e c t

(P R O J E C T _ I D N U M B E R ( 4 ) ,P R O J E C T _ N A M E V A R C H A R 2 ( 1 5 0 ) ,G R O U P _ C O D E N U M B E R ( 2 ))

c r e a t e t a b l e t b l _ p r o j e c t _ g r o u p

(

MX-FrameBusiness Application Frameworkwww.mxframe.net

Search for ASP.NETAdd search engine functionality toyour ASP.NET web site. Features...keyoti.com

See Also...

Creating animations with DundasChart for ASP.NET

Smarter Data Labels with DundasChart SmartLabels

Understanding Chart Areas withDundas Chart for .NET

Making Sense of Geographic Datawith Dundas Map and AJAX

DestroyWindow in VBScript

SmartLink

Create data-driven applications

Page 2: Crystal Report With DataSet and DataTable Using C# - CodeProject

05/12/11 Crystal Report with DataSet and DataTable using C# - CodeProject

2/8www.codeproject.com/KB/cs/CrystalReportNDataTable.aspx

(G R O U P _ C O D E N U M B E R ( 2 ) ,G R O U P _ N A M E V A R C H A R 2 ( 1 0 0 )) ;

i n s e r t i n t o t b l _ p r o j e c t v a l u e s ( 1 , ' C r y s t a l R e p o r t W i t h O r a c l e ' , 1 ) ;

i n s e r t i n t o t b l _ p r o j e c t v a l u e s ( 2 , ' A j a x A p p l i c a t i o n ' , 2 ) ;

i n s e r t i n t o t b l _ p r o j e c t _ g r o u p v a l u e s ( 1 , ' w i n d o w s a p p l i c a t i o n ' ) ;

i n s e r t i n t o t b l _ p r o j e c t _ g r o u p v a l u e s ( 2 , ' W e b a p p l i c a t i o n ' ) ;

First of all, create a project in Microsoft Visual Studio 2005 and name it C r y s t a l R e p o r t W i t h O r a c l e .

Then create a form as f r m M a i n and add a Crystal report viewer control to this form.

Add a Reference to S y s t e m . D a t a . O r a c l e C l i e n t .

Step 1: Adding A DataSet and DataTable

Add a D a t a S e t to your Project and name it as m y D a t a S e t , as follows:

Now add a D a t a T a b l e to m y D a t a S e t :

Now add columns to your D a t a T a b l e as given below in the image.

Your column name and d a t a t y p e should be the same as that in your database.

Create data-driven applicationswith the Hera ApplicationFramework

Towards the self-documentingdatabase: extended properties

Digital Signatures and PDFDocuments

WMP Power Hour APP

Merge Landscape and Portrait PDFsusing ASP.NET

Using Barcodes in Documents –Best Practices

How to Retrieve EMC CenteraCluster/Pool Capabilities

Using multiple keyboards withdifferent layouts on the samemachine

"Hey! Is That My Car? How toSharpen a QuickBird SatelliteImage Using DotImage"

Integrate your SharePointenvironment into the openstandards-based WebSphere Portalplatform using the Visual StudioIDE

The Daily Insider

30 free programming booksDaily News: Signup now.

Page 3: Crystal Report With DataSet and DataTable Using C# - CodeProject

05/12/11 Crystal Report with DataSet and DataTable using C# - CodeProject

3/8www.codeproject.com/KB/cs/CrystalReportNDataTable.aspx

Change the d a t a t y p e of the D a t a T a b l e columns as shown below:

Now save this D a t a T a b l e as m y _ d t .

Now we have created our D a t a S e t and D a t a T a b l e . The next step is to create a C r y s t a l R e p o r t .

Step 2: Adding A Crystal Report

Add a Crystal report to the project and name it as m y _ r p t .

Page 4: Crystal Report With DataSet and DataTable Using C# - CodeProject

05/12/11 Crystal Report with DataSet and DataTable using C# - CodeProject

4/8www.codeproject.com/KB/cs/CrystalReportNDataTable.aspx

Choose Using the report wizard.

Choose the data source from project data which is m y _ d a t a s e t in our case.

Page 5: Crystal Report With DataSet and DataTable Using C# - CodeProject

05/12/11 Crystal Report with DataSet and DataTable using C# - CodeProject

5/8www.codeproject.com/KB/cs/CrystalReportNDataTable.aspx

Choose the columns to be displayed on the report.

Add a group by column, if you want.

Page 6: Crystal Report With DataSet and DataTable Using C# - CodeProject

05/12/11 Crystal Report with DataSet and DataTable using C# - CodeProject

6/8www.codeproject.com/KB/cs/CrystalReportNDataTable.aspx

Now our designing part is complete.

Step 3: Binding Our Report to our DataSource

Below is the C# code to bind our report to the d a t a s o u r c e .

Collapse | Copy Code

u s i n g S y s t e m ;

u s i n g S y s t e m . C o l l e c t i o n s . G e n e r i c ;

u s i n g S y s t e m . C o m p o n e n t M o d e l ;

u s i n g S y s t e m . D a t a ;

u s i n g S y s t e m . D r a w i n g ;u s i n g S y s t e m . T e x t ;

u s i n g S y s t e m . W i n d o w s . F o r m s ;

u s i n g S y s t e m . D a t a . O r a c l e C l i e n t ;

u s i n g S y s t e m . I O ;

n a m e s p a c e C r y s t a l R e p o r t W i t h O r a c l e

{ p u b l i c p a r t i a l c l a s s f r m M a i n : F o r m

{

p u b l i c f r m M a i n ( )

{

I n i t i a l i z e C o m p o n e n t ( ) ;

}

p r i v a t e v o i d f r m M a i n _ L o a d ( o b j e c t s e n d e r , E v e n t A r g s e )

{

m y _ r p t o b j R p t ; / / C r e a t i n g o b j e c t o f o u r r e p o r t .

o b j R p t = n e w m y _ r p t ( ) ;

S t r i n g C o n n S t r = " S E R V E R = m y d b ; U S E R I D = u s e r 1 ; P W D = u s e r 1 " ;

O r a c l e C o n n e c t i o n m y C o n n e c t i o n = n e w O r a c l e C o n n e c t i o n ( C o n n S t r ) ;

S t r i n g Q u e r y 1 = " s e l e c t a . P R O J E C T _ I D , a . P R O J E C T _ N A M E , b . G R O U P _ N A M E f r o m

t b l _ p r o j e c t a , t b l _ p r o j e c t _ g r o u p b w h e r e a . g r o u p _ c o d e = b . g r o u p _ c o d e " ;

O r a c l e D a t a A d a p t e r a d a p t e r = n e w O r a c l e D a t a A d a p t e r ( Q u e r y 1 , C o n n S t r ) ;

D a t a S e t D s = n e w D a t a S e t ( ) ;

/ / h e r e m y _ d t i s t h e n a m e o f t h e D a t a T a b l e w h i c h w e

/ / c r e a t e d i n t h e d e s i g n e r v i e w .

a d a p t e r . F i l l ( D s , " m y _ d t " ) ;

i f ( D s . T a b l e s [ 0 ] . R o w s . C o u n t = = 0 )

{

M e s s a g e B o x . S h o w ( " N o d a t a F o u n d " , " C r y s t a l R e p o r t W i t h O r a c l e " ) ;

r e t u r n ;

}

Page 7: Crystal Report With DataSet and DataTable Using C# - CodeProject

05/12/11 Crystal Report with DataSet and DataTable using C# - CodeProject

7/8www.codeproject.com/KB/cs/CrystalReportNDataTable.aspx

Article Top Sign Up to vote Poor Excellent Vote

/ / S e t t i n g d a t a s o u r c e o f o u r r e p o r t o b j e c t

o b j R p t . S e t D a t a S o u r c e ( D s ) ;

C r y s t a l D e c i s i o n s . C r y s t a l R e p o r t s . E n g i n e . T e x t O b j e c t r o o t ;

r o o t = ( C r y s t a l D e c i s i o n s . C r y s t a l R e p o r t s . E n g i n e . T e x t O b j e c t )

o b j R p t . R e p o r t D e f i n i t i o n . R e p o r t O b j e c t s [ " t x t _ h e a d e r " ] ;

r o o t . T e x t = " S a m p l e R e p o r t B y U s i n g D a t a T a b l e ! ! " ;

/ / B i n d i n g t h e c r y s t a l R e p o r t V i e w e r w i t h o u r r e p o r t o b j e c t .

c r y s t a l R e p o r t V i e w e r 1 . R e p o r t S o u r c e = o b j R p t ;

}

}

}

Points of Interest

My other articles of interest are:

Using Crystal Report with Oracle and parameterized Query (Passing SQL query parameters toCrystal reports)Attaching a digital certificate (public key) to an HTTPS SSL requestChecking previous instance of an C# windows application, also setting MDI child form to a MDIparent

License

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

About the Author

Rehan Ahmad Abbasi

Software Developer(Senior)Al-Jazirah CorporationRiyadh KSA

United Arab Emirates

Member

I am a Software Engineer having 4+ years of experience in variousskill sets.Proficiency in Asp.net, C#.net,Vb.net, Ado.net, VB 6.0, J2ME,Ajax, Xslt, Xml, Smart Device(Pocket PC 2003), and Oracle. Extensive experience withanalyzing, designing, development,and maintenance of Internet,Intranet, Client Server and ObjectOriented applications built on .NETFramework (windows and webapp.) and VB 6.0.

Comments and Discussions

You must Sign In to use this message board. (secure sign-in)

FAQ Search

Profile popups Noise level Medium Layout Normal Per page 25 Update

Refresh First Prev Next

aminer 6:04 1 Jul '11

svknair 22:04 18 May '11

balavenkatasivaramkumar 20:52 7 Dec '10

shebinbackar 8:00 5 Aug '10

amit.kumar.13 21:02 11 Nov '09

SurajMutha 17:51 22 Feb '11

thiru_5862 3:38 10 Jul '09

nitin.mail20 0:57 22 Apr '09

tarksiala 18:32 25 Mar '09

My vote of 5

data not displayed in crytsal report

My vote of 5

My vote of 3

Report without External Dataset

Re: Report without External Dataset

Dynamically adding columns to datatable

Crystal Reports using data sets and data tables

Very thanks

Page 8: Crystal Report With DataSet and DataTable Using C# - CodeProject

05/12/11 Crystal Report with DataSet and DataTable using C# - CodeProject

8/8www.codeproject.com/KB/cs/CrystalReportNDataTable.aspx

Permalink | A dvertise | P rivacy | Mobile

Web04 | 2 .5 .111203.1 | Las t Updated 8 Sep 2008

A rtic le C opyright 2008 by Rehan A hmad A bbas i

Everything else C opyright © C odeP rojec t, 1999-2011

Terms of Use

tarksiala 18:32 25 Mar '09

Roopangee Tandon21:04 22 Oct '08

Rehan Ahmad Abbasi 11:45 3 Sep '08

vinod.chakote 1:52 6 Sep '10

Last Visit: 7:49 1 Dec '11 Last Update: 6:54 5 Dec '11 1

General News Suggestion Question Bug Answer Joke Rant Admin

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

Layout: fixed | fluid

Very thanks

Crystal Report with DataSet and DataTable using C# -responce

Please Vote This Article

Re: Please Vote This Article