Вы находитесь на странице: 1из 18

ntw;//www"cooeproJeot,corrl/ r'\r uulus/ I uu/v r/ \Jtrrlsr4l!-4-rsPur r-uDr. '.

Generate a Report usrng Urystal Reports m Vlsual'Studlo I.UIU - U.'.

;llAlorkrpilrr:$

10.523.188 members (52,037 online)

home

quickanswers

articles

discussions

features

sisnin

eommunity
Search for anicles, questions, tips

help
Articles

" Web Development "

Browse Code
Bugs

Suggestions

Stats
Revisions (14)

ASP.NET ))

Next

Repoftlng

Generate a Report using Crystal Reports in Visual


Studio 2010
By

Tarun Dudhatra,

'S & e

"S'

&

lun 2011

4.85(121votes)

Rate this:

Reporting Made Easy

Type

Arti(le

Licence

CFot

Posted

First

Alternatives
comments {144)

About Article

Eownload Crystal repo* sample - 5C"36 Kfr


Eownload GB$cript sample - 911

20u

12 Mar

Views

637,003

Downloads

57,108

Bookmarked 197 times


Since a long time, Visual Basie and Visual Studio have Crystal report with it. People are saying that since
1993. But in VS2010, they excluded Crystal reports. Yes, what you just heard is right, Crystal Report has
been dropped from Visual Studio 2010. But don't worry, it is available as a separate download from the
SAP web site. These are the things that I found from the internet.
Reports for Visual Studio 2010 will be releosed seporotely, instead of
included with the product ond Most impaftontLy, Crystal Reports for VkuaL Studio 2070 wilL
continue to be free, with no registration required.'

'lt turns out that Crystol

View this article"s

workspaee
Fork this Workspace

Download Crystal report from this link, orjust directly paste the link below to your address bar and it
will ask to save an EXE file.

4b sit
Connect using Git

http;l/dcwnloads.br"rsinessoh.!ects.cen:lakdlm/cr4vs2SlOldRforVS-13-0.exe

C#

ASP.NET C#4.O.NET4

CrystalReports

ffifl%,$ffi
$4. :ffiffi
Top News
klicrcsofl nial<es source
for M5-DOS and

cr:Ce

WoreJ for Wind$!o;s

arrallabte to public
Get the ins;dir Flews free each

found in 2005, but was not able to find any


I thought, let me take a chance to write it for some beginners like me

I was searching the internet for Crystal reports in 2010 and I

particular tutorials for 2010. So


who have not worked on Crystal Reports earlier.

morning.

Related videos

In this artiele, I will show you simple report creation process with screenshots" A picture is worth more
than a thousand words, so I always believe in an article with screenshots"
Let's start by creating a new website in VS2010" See the following screen:

;i

i..i

J'i$arn

'n*+u",Onlffi

W
ffi

'I*r,v,'Snline*

m+sW"ffi$
^+
ir

,:\

*w

,ry',,A

Related Articles
Cry;lal Rcpor1 6aiiiirs arrtj

lileqrai:i0il wilh DaiaSet


'rq l:

Step by Step (rn;itiori .)f C.yst31


Re9oai r.jsrfrE its featufe,
Grr:,rp,

Si:i:il, ar{ls5-Tali

ari

sub R.ep.irl

')'

CryitJl iind Rep0rtinii 5eruic0s


FAQ F2r1

Cry5tal Repnn! lrclFier class

InleqEtirlg iaiosoft Ac(els


DE, SQL Rep.fiing Seruiiei and
Yislal Studii] .N[1
l',,1

I of

18

814120141:56 PM

Generate a Report using Crystal Reports in Visual Studlo

2ulu - u'"'

nllp:/ / w w w. uuutrPr

uJ

uvL.uur

Creating Reporls with SQL


R4rctiii.a! -ipryli3 3ni 1";16:
Sttidio.l'li:1

l,,ii.iiscfi Repotir,E Sr'/i.es rr


fr::

li{?,q|1

Aci;aln

- ${19}

aasi[s of Crystai Rei].,.| f.rr .!'iE]'


Prcgrammefs
*s-*l

(r?6n:*-

Gelrelule 3 Cry:;ial Reporl-!


repairt vJi I houl ; i.lalabtse

k L{{d!*'d..- ?k ir

*+ E: L'{*!4i3!3 lrd

yr:,{ &l.

t di,

How

io

use fr)'si;ti F.4porii i,l

your pfojeci
-{i
**-

,* 'tr,
', ',t: r r,.

Cry5tal and qPorlirig Si)rvirjes


FAQ Pij(

r. $ ': r

q,i.,, 1,";,r,.* *
rt.\
ir ,.,

\A./cikiilg wiiir Cry'5tirl Repcrts irl


.l'J

f:t

Quirkiy add ieirOrts io YoLf


w?trsite
Create a !tr'eb Baseal

Nor-iyl:ei

Cr.rstal Aepons APrllicaiicn

Print L{iiICSali /sccess RePoiL;

iirn

C#

5QL 5ii...tr 20a10 AeP0rt;.q


::ilrvl{:{:s: Crcolirq il rePa)t frcH!

iifatah
5SR! Sqri{il ParL j: Vijrli:,u:i w,lys
of R{ipoIt crei+l:iol, da:ployulilll
ard invoaaiioil

Figurc

Now let me show you


As per figure 1, create a new website in vs2010 and name it as per your choice.
the database table structure.

Dyrlanri{:,i)p{lTis w,tn Micr(1loli


lDCal rcporl enqine

aryital RePofis i{rjJPari fot

'tlARloN-TARu...omer-ordets+i

I
i I
:
r
:

Dtsla

Column Neme

.,.

.....

TtFe ;

Cust ord id

int

Cuslomer-NEmE

varrhar{?o0}

."."....

f.{9w tlulls

L,5ing Fotmula

ii

fjryslal Eepilt

lrll

order-ID

inr

ProduEL-liame

vErchar[fuuJ

ll__i

Froducl-Qty

int

Ef,

.',...,

i:.

{,i;,'i

5hiircFoint

.............

E
,,,::

tr

Related Research

t. ,f]

l , s,

Figure 2

you some
The above figure shows the db table structure. And the below figure (Figure 3) will show
sample data in the table:

o;;#;'i'iinniolr-fi nil6;-Ja;;;r''
Frsduct-Name
Name order-lD
Froducl
CuslomBr 1
Produat 2
Cusllmer 1
ProduEt 3
2
Customtsr 1
Producl 4
?
1
Cuslomer
Pr0du't 5
2
CustomEr 1
Produrt I
3
Customer 2
ProduEl 2
3
austqmer Z
Product 3
3
fu5tomer 2
Product 4
4
CustBmBr 2
FroduEl 5
4
Curlomer 2
Froducl t
5
Cust0mer 3
Produrt a
5
Customtsr 3
Product 3
6
Customer 3

i.tiliifrrii[il.-;$;*
ll

'au.t

;r; id

1
2
fl
"1
I
l
il

t
ll
:li

i:

t:

{ustomer

.-....1".d.y-'j-sry

Hovr lo Seclir-.'/our Software


ior thc l'.4obi1. Apps t iai kPt

5
3

6
?

lr*n

I
I

li Th.Wils Testiirg: il.)w i0


e;rsilre'1oilr AirPs Wcrk ir the
Real Wnr:d

i"

It
Figure 3

link
If you want to run this sample project directly, then you can download the database script from the
at the top.
type. Here
Now we have to create an xsd file as a blank data source as we are going to use strong data
I will divide this tutorial in 5 sub sections as mentioned below:

t
.
.

SimpLe report using Crystot Reporting Too[

Sub repoft

Tne ir;sentiai Cuicie to I\.'lJbile

App Testirtq: ilPs for


Developers irr !1!A &- Carraca
.. {'risY.r.:.',

,..i{ ,r"

i:iii\\t$f;li.ii

Group repoft
Chort report
cross tob report

..-:
Eest Praatiaes fcr 9ealJt|\1o'l

2 of 18

ar(

8l4l20l4l:56 PM

Generate a Report using Crystal Reports rn Visual sttldlo

Ilttll:/

/w w

r.!.]

;i;,tl

For adding an XSD file, click on Solr.ition Explorer


and then itwill show you the below screen.

ftfVtJ

-> Right Click on Project -> click on Add new ltem


.,.. l& '.

sg5-;"**,.&1
k. - x.1",
g.&,

Csrtificatts

ilr,,r::i--:i
!-

The below figure shows you the pracess to create an XSD file. (O

,u*u, XS*
ilEW Frai}r{t
t* ;;"tu*,t -l*!
YY*
t;'j-:"#"+ig#j W .*ti iii:=.il
: b jo*us
ll;
"
li,i',e;ffi

*{6

ru Lrvrvr/

w.\.uuEPruJ eu r. uuu!

Private Kys anC Ccd 9igning

.,.:... ;:....,,
t..rir".

zulu - L"'

,nryr

Y.:?::::':ti

,l

rnilattiii r-qml*atai
lliud E{ct
udurl C*

..,,,,,,,,,,-,...,",,

.,".,,,,';:.,',,,,",,,:ie.,',]". " 1.,:, .l:.. *';'e-;


1].t

Sd by, , pgrutL
*'

-i**

ffi

; .F.: ' ..1-

:.

ti$ual

v,r*us*reenm!

dlx
io".)..

ADO,NET

AC4,NET E
fii.ij

Am.

I'JET

Viffif Cf

EntitySalEt]o&l
*ityob,wt

5df

. T! ae

l.i''q

nillv Sener

..

viMI 6 f

!$w

(*

Sfui

${+x-ffihb,l vr(F srvire

Virffil

$-]f,
tii$$

s,*uu* riu

lrgsl Ct

crxs

viiBsl

#.1
,li".l
-1#::
;n:1

,'.*f
l-

ffi

ct*r

uror*

f*

tsusi L#

{r-}stal *eFtrts

visrEl CS

o*os*

rvjwul,(t

nrrur';enxa'r*u

ViffiiC*

i:r:r:.:=
I

lr:
.:.

i'issla,

GffiretDr
E

*"

ll

Figure 4

Click on the ok buttsn, so it will ask for confirmation to put that file in App-Code folder. Just click ok
and that file will open in the screen as a blank screen"
Now we will add one blank datatable to that XSDfile. Just right click on the file and select Add ->
Datatable. Itwill addoneDataTablel tothescreen.Figure5showshowtoadddatatabletoXSDfile.

:::::Sdd]:.=.:

,5hary ne-kiqion t

;r:l

::l

dhels.=.

,:..::1:1;i:i:r:'::.

rvleN;ig0dEr:i : i t:i:

Pron+lE9

Figure 5

Nowdatatablel" isaddedtoXSDfile.Nowwewilladddatacolumntothedatatablel asper


figure 6. Remember whatever fields (columns) we add here, it will be available to show on the report. So
add column which you want to display in your reports one by one here.

of

18

814120141:56 PM

zuru Generate a Report using Crystal Reports in Visual Studlo

Detii;g
,.i'l* {' i u'lg;,,:}LY,"b.''.'},?orLt BuilJ...;...1
-.,r
d.
:i
#,il
,idr.i*r=.+sG

u"'

Illtp:// w w w.luuvyrvJvv!'vv

AFB-Codei dt56mdgrxsd*

Tlr.l(..\4;ili

Add

+r

ilNiif rr,|,

{ut

fr

{trl+f,

:::

eii*I..i.ii

{trl+C

L!Fy

ltrt::'
P6letB

Ckl+L

Cohrm

i.*

PS

f!d

*enara
4dfssi]']-9..:

ViEW'(o,Js
+I,1t *:iiF.s

Figute 6

also select data type which


Remember to give the exact same name for data column as in database and
mismatch'
type
and
data
for
field
is the same as database, otherwise you will get an error

asithasin
onceweaddall therequiredcolumnsindatatable,thensetpropertyforthedatacolumn

Default datatype for all


database. The below figure will show you how to set property for data columns.

thecolumnsisstrlng heresoif datatype isotherthanstring thenonlychangeitmanually"


datacolumn in datatable and select property and from property window,
select appropriate datatype from DataType Dlopdown forthat d3tacolumn'

Just right click on the

Pr6&ttt-Qty Datnfollmn
!:.{l
.:. *r

(u$[smrr-],larnB

':!rdor*Ir
Freduul-ruEm&

:;,
::

: .

'r

All6t!08f,lsll

True

&er,rytrft{r6ilent

False

8iltttrfl{rent"nfsee'l

,,.1

*uio!n{it$*nfStep

Ldr{lgfl

Prsdu,:t-qtf'

*,!ie:[yp{

gys|:*fi,5hing

t'3letiroelt*,ie

un*p6rifiEllo{El

ii#fllilrtaluc

s0BNull';,

I
I

rFr*a*i*R,
t

tJ*slq

"t
Prilduct*Qty

ll#1!r"S$s

{Thr4il axcetntlr:u)

*raddntr/

Fal$s

ilnqu*

r&ts6

Ftiilsndh

,,:-$n

lt (i4

,:+Ii ':,::

'i'

,':

X *d**
lH$rl.{,$uffi
-r,*a

-::l
l:i';

F,xinlstl

,.1

fbr

. ..:.

fiEdE.

Irg FrBHtis

r"a")!

fn:
,*i+iietr

*rc,
repoft design'
That's it. XSD file creation has been done. Now we will move to create Crystal
crystal reports" Name it
Just click on the Solution Explorer -> Right click on the project name and select
as per your choice and hit the add button.
Figure 8 will show you the creation process of Crystal reports'

4of18

814120141:56 PM

r u - u"
Generate a Report using Crystal Reports in Visual Stuc[o /u

'

IltLP./ /

WW

W.UUUllJr

uJ ww

$!

vv

ffiffi

!shilleil

Tmot*res,

?'lcml E&sie

Ui*sl C$

Figure

it will ask for the report


click on the add button and one.rpt file will be added to the solution. And also,
you
sereenshot'
a
will
show
Figure
9
report'
the
create
you
want
to
creation type of how

.'.;i ;r',"*'clo;pg ip;i

l=,

[1f {irl usins the neport Mzard


[-l ''i*r u ehnkn*ort

,@

li.irru*u'l

t*ri!i"il$.,

{hacre ar Ex$ert

e
[.i]cross-Tab

i,

:.:,
!1

i
i

:1i

-----

Guide5 the Ereation ot a typiEl report,


l

il.*,*,i-,!=-{
Figure 9

Just click ok button to proceed' It will lead you to figure 10:

of

18

814120141:56 PM

tILLIJ.// W W W'vuuvPruJwer,vvr

zu I u - u' "
Generate a Report using Crystal Reports in Vrsual Studlo

Figurc 70

add to the selected table


Under project data, expand ADO.NET Datasets and select DataTableL and
>
button'
using
windows
of
the
side
right
portion located at the
Now click on the Finish button and it will show the next screen (Figure
{.1.+;t3S.[. *@.,

"
ta

,tr j: -

:iiti::,::,=::::j- i;;:.Lrt .ri 1 ltr.lt::

, t,i:. .:t1i:.i;
}|i'lll il i

q Lll..r,tu
'"8::::J.i9

tii::urFl=
tr:::;,iiiilritr'
:iJi.i!-!:..:=

i,,"i11

g s.E*lo

"" :rSBlri

1-L):

;:litllr.:

*1f: ll]', r
F,tkr8."iri
il

1,1

mLf:

&d!15:@s$j.si xy.w

sir*;*!
sJ,:*rrs

::.i{.hflliqs-ii,}lFr$E.l-rt-,,:au;;..=ii;i:i::::'a,

:::,:,sgii

':.,

riii

l::'':'il ir:..r,l ljr!

.lhe

4$.ie!j*4
N/@il-lS

tr,,,rriu !r.i."- : :s{urjdg


'-;ii*t,",-irrii*,,n,uur-.iru,t+

3.,,",.'r'sx,,ot.
i if;ir'*ris,
i ;: r+rii ";d

+'d\?Jret4+

:rd

:ll*i:rr,Yt,'il-tit

1{#i;i*l
hzldild$,

J..

ii f,Ft

!t! rk?,

i.ilhhY

elrr r.]ff,

{i

4e@!4t

i]!B*3tF

4&ril'r&

(*,@t*r..$#t

i{rtra}!$:

(lf-..lt*

n6'1 I tur [.#4 led,

Figurc 17

once report file is added, you can see Field Explorer on the left side near server explorer.
earlier. Just
Expand Database Fields, under that you will be able to find Datatable that we have created
expand it and drag one by one filed from Field Explorer to the rpt file under detail section.
Now the repoft design part is over" Now we have to fetch the data from database and bind it to dataset
and then bind that dataset to the repo( viewer.
Let's Eo steP by step.
First Drag a

6of18

CrystalBeportviewer control on aspx

page from tool box as per below screen:

81412014 1:56 PM

Generate a Report using Crystal Reports rn Vlsual Sfudlo 2UlU - U...

Toalbox

,. r$3;

ii: 5tandard
lt Uala

f ryrtalReportvieHer

,i,l'laviEaLion

Ex!Br

oozv

\rsuErarE-a-rsPUr t-usr...

)$:

- Cry5tElReportvi6werl

Use the ReEsrtsour(elD property

+ Loqin

slAx

Asp4simdeReporl,a5px

.t

l he.d-v,l

ii..1rBiidatisn

i"n

http://www.cooeprojecl.com/Artlcres/

ts tpecify n Repqrtsource conkol

l?if-:,nr

rlD'ynanic Deta

iiiRelorLing

t
$
:f
3:

Fcnler

!s

r_rystBtRepotrPEt rsulE(4er

i};

fr'/rtalReporlsflure

f,eFsrltiEHer
CrustalReoortviewer
:.1

Figure 72

Now we will fetch the data, pass data to the dataset and then add that dataset to the Crystal Report.
Below is the C# code which will do the job:
E aollar3e I aopy Code

using CrystalDecisions. CrystalReports. Enginei


using CrystalDecisions,shared;
using System.Data;
,

us

j.ng System. Data.

Sqlclienti

using system. conf iguration;


Below is the final code for reports:
E {0liapee I Coiry COde

protected void Page_Load(object sender, Eventangs

e)

ReportDocument rptDoc = new ReportDocumentOi


dssampte ds = new dssampleO; /l .rsrl ftLe nane
DataTable dt = new DataTableO;

/'/ Just set

thE naye

af dcta i1hl.e

= "Crystal Report Exafiple";


dt = getA1londersO; /lTh1s functicn is Locattd 0el.ri, this funtticn
dt,TableName

ds.Tabtes[0].Menge (dt) ;

YaLir "?!i .fiLe pctlt xiLL be beLctu


rptDoc. Load (Senver "MapPath ( ". ../Repgrts,/SinpleReports..pt"

ll

))

/./st dGtas{t'to tlte report vitBet.


nptDoc

SetDataSource(ds) i

= nptDocj

CrystalReportvieuerl.Reportsource

public DataTable getAllonderso


{

//Confieat:"afl string tplac 'dstabilsesr\Jerna{ie' with youn db serter nisne


string
sqlcon = "User fD=sa;Pvl]D=sa; server=datahaseservername;INIIIAL

CATALOG=SanplelSj

"

"PEtSlSTSECURITY INr0=FALSE;Connect

Timeout=4";

Sqlconnection Con E new Sqlconnection(sqlcon)i

Sqlcommand cmd =
Dataset ds = nu11.;

new Sq1commando;

SqlDataAdapter adapter;

try

con.openO i

It

i.s aLready i.n sanpLe dD.


1.,'S?.ore{i prccedur{: .ol.l.i.rg,
cmd.CommandText = "getA1lorJers";
cmd"Commandlype = CommandType.StoredProeedure;
cmd.connection = con;

ds = new Dataseto;
adapter = new SqlDataAdapten(cmd).;

adapter.Fil}(ds, "Users")r.
)

catch (Exception ex)

throw

new Exception(ex"Message);

f i.na11y

{
cmd.Dj.sposeO;

if

(Con"State l= Connectionstate,Closed)
Con"CloseOj

return ds.Tables[0];
)
Now just save everything and run repoft. It will look like the below figure:

7ofl8

814120141:56 PM

Generate a Reporl using Crystal Reports in Visual Studio 201U - C'."

#)

F+v:rier lisk

F;+p

erLF,i/.((*.r::qgSq.6-#rArpx/;ftpleReF6ri.$r,

-.liii,,o'-"...,,.::.
:::3

f,laiE

REFcrt

!: l

$il

--.

lNrlrtrir

'l

Pndurl

tr.a.1

lii,r,fl

F,r..,.:L:c1

i.Itri*.m,irJ:r.siri

;rllnilqr

FD*urt

lr

Pl?aucl 4

FEdur.i

Frc:Lfl

r-' il

,]
1

Fr*ds(t:

:*itafior l

Figure

roo./.v Ltueflerate-a-report-usI...

,ie}+a$l

FllB Edtl lp8

' Fa!0r+ei

http://www.codeproJect.com/41'tlcles/

!r

7i

Grouping in Crystal Report


Here we will see only report design and rest of the things, you can refer from Section 1" Here we will
group Customer, Product, Order and QUantity. For details,iust go through Figure 14.

Just add a repoft (.rpf) file to the solution. Select the appropriate
it's done, then select grouping option Iike flgure 1.4.

i
,
'
,
:

dataset

from popup window. Once

SsqF&p$r|"ry1:

i.i EataLa;EFidld*
EI Fomr*ia iitldr
Lrl

tnrrnlEiefsrlfJ

Grnug lJsnre FieLlr

!EunnirgTcial

!1tr'l

i?iffi tiffii*

i:iLi{lLrr:l::. : i:,,

i..Lt

$i?:i::r::+:::rr r;.:-;

il

l*.t!:i:=

Fieid:

r. jt: \p4:r3l lrdrdt


i; ] lJnbmrd Fidcr
lnerd

;;;;;.-*^
rl
ri

$.*3olt
Seii$n

I
!

I Srvien N,eprd
+ . rrtll LqiuEi

I
,3reup E*pext.""

i..---".--------

Swiriev: Rrperl

f'r:iti:f:I!1iw

Yir+

:an
:s

Figure 14

Now, right click on the report, select Report -> Group Experts and the resulting window will look like
figure 15:
gBUp.FoBSt X

I
:!!

FilabrrE Fanidt
Fermdl,

,r.1
r,i
| 3 r,i
vScaiolFw,-e:r,.",.

Fi$!d5

[? 0ar6Bs"6r aleld,
.8. trcu! llnm: I rtld:

Alrtilrhle ilEldr:

Jlj
i

1 !,r

!.s,r.{"r,i,r,8

r,.-

SaerF

ri.

BI

P.ep*rtFieidz

;r a(rtaffilt,hlsmE
r:lrear
l,
5 P.it<J6tt-l,litrt
! p,aCsat_Qt!

0iar$5r

16i$,". I ti*d

Fielii.",

Figure 15

8of18

81420141:56 PM

benerate a Keporl usmg Crystal Reports in Visual Studio 2010

_ C.."

http://www.codeprqect"com/Articles/

629 I I Geterate-a-report-usi.

Now we want to group like Customer Name and Product name so first add Custome!- to the right
Panel. Then move product name to the right panel like figure 16:

it
*l

llrtabirs Firlr]l
Far$f li Fi4iil,

i?] Plrame.te',

i:-!:"1i-::.9

g
g

Lrr up

rurF'4q ,
S sp<;t) Fir:{d

Lrbbc4 x r tq

Aliii{?Eh ftEIri:

Etr:

m.rg

EepEFF,Eld::

_.

L',llldlal
t: tlucelrcr-i]eot

;:.

garirlrrer-iliir;*1$ars*

fi'i

lji

-&

hl*-L-pr$Cr{t-i.]jse - A

-3+lrZn

J) +rdef lD
.,ir Fr6dl:t-firtbe

-, Fioilr&-ql}

Figure 76

This time Crystal report design will be different than the previous time. See figure 17.

GroupHeaderSectj.onL and 6roupHeaderSection2 are added to the report designer. Here Group
#1 Name refers to Customer Name and Group #2 Name refers to Product Name.
And also GroupFootersectionl and
something to group footer"

6noupFcotersectionZ

are added below if you want to add

1, !& Bltiil.nefili1:
l?l Paramgter

FieJdr:

, >4
n utf Jf, rldff t'!a,ct
P,Bftnift-q TotEi Fiald.

. =
-t. )pcirJl rrerul
|.: tJ[t]ru1{ ilrdi

?,9adi$3

F&gB

lt){$* i

GeEne+l$5rg.o"

roE(s l-idtr: l::hlE-Ietsrl

Sroup #1 l{anr

Cra#Hader$s1,ry,: $6!p ba6s

EiouB #:

tlam

L,t+*q-.r*

.r:

FrJu*-la+

*qitH:,t

"2

v'.1@:i# sct#.- Srrp Ig


,:s: Srsr*!4.Fqps!: f$sni.

se-iti{$ai

(-aoTlle1

v ;DJplslessctdJ rlEtp t@s

ii:

Llsffi_igH - r l

#.ai6 fl1rFf

ld;;ebel.PFJ-C_13rc ..i i

;1. 9o1u18!4 1.alcrc'-idsmr

Aj

:i;:i:

Figure 77

Now under every group, we want to show the number of orders per customer and productwise, so for
that, we have to add summary to the 6roupFootersectiofl2. Refer to Figure 18.

: dS SaGbarr FieliJ,
i i mBrkTiSld
aPtlurlnnrer-liasr
:
e7 ittleUl
:
q! F,oCuat_l.lrrrr
,r;i

r.3

{.

1m_sf:i'1,!!*tq.

F,i?$r

tl;,J
imelc! )rclJi
, '*' j d!c l"r.ri L,Ell:
.

,i.l.i-:
r-,. f,i."di"i,f,:

Prcluf-rllf

ikl F$rntir,,

B.orprqls!.apia :r

flJxnune :.1n, Fi*l,li

i EipErinllidd!
i : ,.lnbn*$d li:e5

h.ile.r.)[i

v &lupFas;affi1 u'+iF heae ;l 3elffil M6ei_tlffi


.6,oufl *1 lldrne
v .iEUF reryle*r r_,rirs {i es@ ;J:.il{e @ E Jud-I.#
$inup rz

ti'iili

tliL$*:aii.!-tjfis:iuJ,

iir.iiLLriru:,,

? :epF<de 3d:ft.J ict,+, icee ;:

fi,

9 of 18

j I J;,

1l.l

dd :rbld

t.tfte-tl

t:tea

lrtriri ii. o r

Sutrbore

I I ::j i

Tr'i 0n-iEc

t
l

..

ffi
.

Fe:

'vrtyrar,..

81412014 l:56 PM

http://wwwcocleproJ ect.com/Artlcles/

Generate a Repofi using Crystal Reports in Visual Studto 2010 - C...

I bo

lv r I lJe,Jetate-a-repofl-usl..

Figure L8

selectlnsert->Summary,ltwillshowyouthenextscreen

RightClickontheGroupFoctersection

Order*ID and Produrt-Qty field to the detail

(Figure 19). And I have aiso added

(section 3) pad.

*- .]| nitdkti iirCr

lil.l..-".liJiliir*.:;;:-:rt

..si/lr.1r"lR
's!,irc du.1,i'itsme

t'*ou*'lT

r I:! Fsial*!6

i'

"1 r '':..-r

:5{ui:lrma;-tt;ma

F,EIJ:.

:kl:- Y

j.,.:-l::::.1:\\-\\

:::li:l:l'*:

t,r, 6*1"1"614"Pa*.t-*t,

iiltulel* thi: jEffi fi *rrr

, l?l Fgrrmoter Fiald:


. g(1r*!!. rulnr rrflrl
'XElrnirg?qtilfids.
,,. E !re*rl l,Ellr

h---.,-r..1
:i ::.

tt! :ra::.:.:!ti

iil-i;_l)i

:,.,. :.;r:ja::::l\

:.:l::l!.;l:lrtrA;r.airi;..,.:.r,r:!1,.i,il

.r .-lnE0unflfar)r

!iltrrnrary ib(i..11s6
i-r-;lllllllllllll

r''i Adri tc

alil

grcup

lllll*

ii+i:r-ntl

6Bng T6til iBEFe.if6dsl

ler*l

Figure 19

In summary window, select the column which you want to summarize in the first dropdown.
Select Sum (First option) from the calculate drop down.
Sunrmary Location is already set to the report footer. So just click ok to place that summary field to the

report.

to the Report Footer section so move it to the


wise, move it to the GroupFooterSectionl if
you want to group Customer wise or keep it at original place if you want to sum all ordered products. I
havemovedtotheFooterse(tionl soitwill showCustomerWiseTotal Quantity.RefertoFigure20.
By

defaul! Summary field

is added

groupFootersectionz if you want to group product

ld irit

6,e.

+fE!Ba4F{..:g!1..

:: {Sll:::=". rt;;i;;;

ffi r-.--'sr.t
. e} (,"!tL n,rr iJ.n!.

, qtFrq*utt.ltunre
sg,Frejs{Ltbi
,
i M Fc,m!'la;ielCs
I li!,idh*r
t rrld:
! e:rqulsrirl(-'*ui
, $tunri*g3*trl iitld:
i t5tECi, r'0i
i.
.qrC{ciIrtl31

';;-"-

'.'-F:',----

:.

',

'

^..-",^.
:.]J-]4
:ru .A.
v 3rd*a&kanl
--.eo ii8s;'li Daal.ohl.:s@
-ir0up #{ IIam
,
r ;4w.+ady5*ds0; f4* tsffi !; f esTipel.Fmal ljme 3 ]

fi ro$P #? ll

'

,-

lmP

{,-

566a3ltHar.

^ ilr(ir

rD-

-1!.1!-"1X;qi,i$rffi,f,I _r|-iry+...1i!.e:s,#;,flS.,+,,T,$.,-!hj,!.fed.k:.

v (l,owimsSri r I ti@
? l;SrJiFwd lsfis

Fef *r +L $ddTab+

*i

iriffi -:(e,

{iffiliitiiiift"'--

Figure 20

Now save the report and run it finally. It looks Iike figure

10

of

18

21

814120141:56 PM

Generate a Report using Crystal Repods in Visual Studlo 20lU - U...

urder
Custamer

nttp://w-ww.cooeproJecl.aofiu-SItlulgb/

oozv r/ \JtrllcrdLtr-d-rtrPUr r-udr" '

ProdLrct Qtv

ILJ

I
Frotluct

Produci 2
Froduct 3
Froduct d
J

Froduet 5
6

73.60
Customer 2

Froduct

Prsduct 2
J

Frgduet 3
5

Figure 27

Chart is the most important and visible part of the repofting tool. Crystal has very powerful feature to
add chart in report. Let's see how to add chart in CR. Here also, we will see only designing of the chart
for other thing. Please refer to Section 1.
Here we will show customer wise product ordered quantity in chart. X portion will display Customer
name and Y portion will display customens total ordered quantity.

First add charts to the report design.


Right click on the "rpf file and seleet Insert->Chart. Refer to figure 22.

G ri.r,SqllrttF$i i{
& Ortab$e

I't

Fieldt

:, I, i.

$drtruln fielde

t, !.1!

3 i r '4

r,5,

tA.

r'7.

r'8'

I'li'

I'18'

r'!,'

l?l P{rtn1*te1 sieLd}

$6reup tl**r*Fitl$l
Eftu$nl*E tals, F:i*ld{
:L )pe{rBi I"r$d:
un&rlnd F'reidi

.vsatm},ffi l,
:

rfl5rrt

Seom4lEmn

,"@---,1

glurcei

'=:i;

qoeftal freld

l ,

.--.:--... "".... ......,.....

, Srtrb.ru

Foas e.
v lerm5 ipae tpots 'i ou"gn

i-l

r:;;1i lut0bsect
**- {I
-

s"n

tontrot.'. i

iri:rrtra
r ., ..is::+
-.; A**'.,,
*----': m:i
I
--.*..*-,, ,i pt&;ew
F'cport
Sdctian "
:

,l

Sst[516lats";

f
$

I m,i S*ttePut*

; Prb'Ou5 XtPofl lreEJ

L,fle

, iileit Rtro,t fis


: ,:r.:j

Eox

Caa't..

S
m-

Pielure'"

;;;;;:*-

Figurc 22

Once you add chart to the report, it will not show chart on the report file but with mouse pointeryou
can see one blank rectangle is moving. Sojust click on the Report header. lt will open popup for chart
style and other options. Refer to figure 23.

ll

of

18

814120141:56 PM

Generate a Report using Crystal Reports in Visual Studio 2010 - C...

http://www.codeprolect.com/Artlcles/

,
r

/Uenerate-a-repofi-us1...

Mt

fkaet qxpe{t

t Oozy I

.*-.0 ni*,

*a l
l:X!
.r,

silrdrtt
ss.{E

f*lr,

s::'*

.
ri:j,!slrurt av-i

'

{2. &urg*

kI iidrh8rahid. E6s disFt6]** $lqcter*th qrtsf en* arbg.oup


io6tlor+ll. 6ced lor rhcxrBg (noipiriFnit:e&wf, *EuF xialut,
Sidr

ii,e""tt
]Slunret
,

i,l' Hi*oo.ao
1I

Figure

i$l

!'.rtird

!l

'

Urr d.pth r$ect

qriFstni

2l

Now from type tab, select type of the charts like bar ehart, line chart, pie chart, etc. form the left side.
Select sub type from the right pane like side by side chart, percentage bar chart, etc. I am not going
into the detail of it. I am leaving it for you to practice work.

And also seleet vertical or horizontal radio button from the below section if you want to change the
chart style vertically or horizontally. Check Use depth effect check box ifyou need shadow effect on
the graph. Refer to figure 23.

Dita

icil*bl* iFlde

ir.{..-1::.&el$tfl

:li..r;iiLtrliu::.=r..

D{teTJgkl ,tlJtsms-1tr!flr

,.*i Fepqx Fis*u

lf 5!ftFlslit$d-L &f3.ri!T

" ,q

{.tl}iL.j

u {Uit*tslsr.*}lerre
*r A"J-.!n
u Pr*aulrt-tlaoe
u 9lrdud,qiy

i a r:r"1:-:: l:...- .....i;i

i.:,' rw;.,

t'--'-^..^-."-.1!^
id

{r,.n+-liri

i':rr.r.iiira

Figure 24

As per figure 24, move to the next tab data. There are three boxes, available fields, on change of and
show values. So move Customer Name from available fields to on changes of bo& and move Product

Quantity filed to the show value box and click

ok

Now you can see chart is added to the report header section as per figure 25.

12

of

18

81412014 1:56 PM

http://www.cooeproJecl.colll/l\rtIUles/

Generate a Reporl using Crystal Reports tn Vtsual Studto 2UIU - U...

oozv l/ \JtrIlsraLc-d-rtrPUr r-u)r' " '

"epiFegsrl, rp:'
.

/ii trgtsbslc Firkl:i

'A! FtrFrxl, Fieids


l?l Fa;;meter Frrldr
3 U-.uF rljrc i.e.c:

HErnnisfl Tdtli l;.lil!

sN(iil Fie;c!
*X r-h^ ,-- a,-,rr

.:

1,{

3c"atrr!

t: r{

i,J.,
i.r,3
:ie.d hdH l

i.i",'i,
,

!.$.,
-,!(!jr,.,.....::r,,,

ri

1r' r'li')'r:'i
"

., :.irrl Li r,.,,,,.i,11

r,i,

$um of Praduct*Qty I Custorner*Name

:
'.

""'

;{:

eE

:l *.,"

'l

.r

iiI,ft, iu-!.Sr-.tf,#ilii,rr

Figure 25

Now,just

save the report and run it. You can see a Report as a chart on the screen.

Crystal reports provide reports inside report feature which are normally known as a subreport feature.
Let me explain it in detail. Here also, we will design only sub report design" For rest of the things, refer

to Section

1.

Add new report to the solutlon. Then add Report->Group and select only Customen name because

wewanttodesignrepodforeachcustomer andsubreportproductwise.Sotherewill beonlyone


group header inside the Customergroup header as perfigure 26.
Su3Repsri..rpt

:-{

4$ Databa:e Fields
i.l;

tI

E] oataTsbkl
Fqrmula Fields

I?l Paranretrr Fields

E
f
t
]

br6up l'Jdnre llel6s


Rlnning Total Fields
SPEClal Freld!

Llnkound Fidrls

{srupHeadqrFdion

1 16roup

-6 roup #1 flEffe

?:gF.tL?rln[- !k].:?"ffng.rks.fl1

A,{

F-'-..,tifl.lf .f,.,,lF,..4,,1lb,iliiiLLriii,,,,,,,

y..,.qpyFti,#.,fi s]-$mHr,Fifl,f=li.!4p,r,rHriliEt*g.g"ilrnr.,:#

sef,tron4 fr&eal Fa0ler l

)Edrod] lrEge

tmtr ,

tJumrei

Figure 26

Now right elick on Detail section and select Insert->Subreport. Refer to figure 27

13

of

18

814,20141:56 PM

Generate a Report using Crystal Reports in Visual Studio 2010 - C...

:::

'j

6ozy I /uenerate-a-repofi-us1...

lublcprc.rpt }
Databast FitlCs

r"4 i.t
i,r 1 r';.r'3
v
Smiml {Eem* Hader l.
!-;-::::;: : :,::' l&-- }

it El DataTablel
l.-x-t Fcrmul'a FielC:

i.[?l?rrameter Field:

; E

http://www.codeprolect.com/Arhcles/

brouF Name

Frerf,E

Heff;r}

9ectrnz,{Page

r.fi.r,?.r
*r ., ..,*.;._..

.....

i....$ F.unning Total Field:

:-t
t-,.
';!

5Fenal Freldg
llnbn!,nC FlElCg

#Grcg;Nadasectiftil
roup #l llame
-G
trYt*rff

tctoup Header

Fffia

rt*:le

Custorer-Neme

'+r1i1g11tih*u(i$-i,,*rrH,,.;;srliiiiriir,;
' 5pecial F'iefd )
{i,!

J,*CItj:f

..

5c*t Csntrel..,

"t

9er$4n..,

flEl0 Hp{orer

f,rass-Tab.,,

Suhrepr*.,,

Eh

i.'r

:.t::.t::i

Group".".

Freview Repuri

i' i

..

Sumrnary.,,

i--'------

:i

,'r

Preriisus

Eepo*Yim' i

i Linq

;*;.;;;,;,'' .

il

dJL

Es
aharJ

Figure 27

Once we add subreport, it will show screen like figure28.

;ili'1

0r-demand:subrepcrt

{similar to a lryperlink)
i

i*;;ffiiil;
Figure 28

in projectis selected ifyou want to add report


from the project, then otherwise select create o subreport with the report wizord. Once we select
As per figure 28, by default, choose a Crystal Report

create a subreport with Report Wizard (3rd radio button), we have to click on the Report Wizard button
to select report type and data sourcejust do as Part - 1 first. Then click on ok button so llke chart

report it will show a moving rectangle around mouse, click on the detail section where you want to
show subreport.
Now to edit the sub report refer to figure 29.

14

of

18

8l4l20l4l:56 PM

Generate a Report using Crystal Reports in Vtsual Studlo 2UIU -

lrhPieFoE

nltp://w-ww.coocprujcut.uulrl-/futlurtrb/ruuzTrluururotu-s-rwyvr!

sDr"

rFl- o

.r,1

U"'

1'+"l

r":.

!,i

S^ec*rm3 iPaEe

liearer ]

- 'Prnt !-r*lp 'J


. t "' ---

l'3'l'3'l'i*'l

l'g','I

^GmrHeadsgs;or
. Sroup
#1 tlame
v Se*rs,.3
i
--;1 :tilelaEs :--

iGmp HeeJw i1. fi,*a

J aoie

l.Custmx-l{ame' A'i

iProduct'r't'ise
.i

Y"

--

EditSubrePstt

rb

Frrmat Sbjeet

"l-r

t
I

! -.v rormat PBinler

vsecryrltieltrIlPfEJ
v

Chanqe SubrePart Links...

&i
c

Y:,.

Smrm5{Fese .Fmter ;)
..
6.h;.

[ t'lumrei

Figure 29

Click on the edit subreport option and format the report as per your need. Here I will suggest add
product name and product quantity or you can add chart also for sub report. When you click on the
subreport button, it will open subreport designer, aetually CR will create a separate.rpt file but it will
remain hidden inside the main .rpf file so we can't see it..

Now run the report and you can see the result, repoft inside report like figure 30.

a:-$3.2[

E IUB

1 "ft1

"1.11 1

P ro

cuLl *

1,

1a!91

p!id*:t r:3:1f
fireil sls

li.4q

i:+i4
3n5:3
t

36ld

Red
ffa

ii
l"Jsril

!:: :t:
t:: t::::

jl

.. .

t.. j*t

Linne

.",
dni ,

NWi
;,i
*r
":ssy,

t:::::r:-::":: : r:1:11:r':a'a':l::'ll:

tr

l,,lain F.epcrt

E ldair fupa* Frevia,

Figure 30

Here number 1 is the main report and number 2 is the subreport it's showing title as Product wise

First, let me make it clear as to what is a Cross tab report. Normally, we generate report row wise like
first we show Customer name, then product Wise, etc. But Suppose we want to See report as column
wise like produet name should be displayed as column in report, then cross tab report comes into the
picture. See result of Cross Tab report in figure 31.

15

of

18

814120141:56 PM

http://www.codeproject.com/Afilcles/

Generate a Repoft using Crystal Reports in Visual Studio 2010 - C...

I Obzy I

/uenerate-a-repofl-us1..

Itiih ftf,pert

Prsdu{t.l

Telsl

Procucl I

Prsduet 3

ii.0A

+.{}s

5.0q

3.0{

E,SS

ClstsmEr 3

2.0{

3.tls

5,0$

3-00

8.00

31,88

Ulnloltsr 3

9.0s

.{"tE

?.00

5,0{t

?.ss

3L06

f{6ttnx.4

6.0{

E,OE

fi,s0

?5.0{

IlL0s

$:1,i1$

1?,0{

5.S{

3-0s

0:ss

t.fls

{I.{}g

53"00

?6.0{

d!.08

36.ofl

1?.f,8

1s3.fl0

Cu$lGfr8{

C*gtsr.er
Toisi

Fr*durt

P,sdrst

Figurc 3L

Here also, I will show how to design cross tab report only, for rest of the things, refer to Section 1.
First add .rpt file to the solution. Then add cross report to the Report Header section as per the below

figure

to figure

(Refer

32).

Remember we can add cross tab report only in Report header or report footer section.

f,rpsilcl.Si:
. 1,1. I':'r,3,t

:e

'l .A ' | '7'l'!'r'9'l'1S'

"4't'F-

v lqyrl tPoglfeuioj"*

l,'*r+*!,d.

1Yry'
1

Insert

:
l

,l

#J;;;
Eepert

:1

BesiEn
1

.l

l
iil

i.i*:* illaq:rr:
Pr*.i*iftrp,rrt
ilErs gptorer

Fra.iou:

Repnrl'dlr*

ll*u'r:nu:*'

.. ...

i,:lr

htg
I

Line
tsot

f,hart.".

it

..:

Figure 32

Once we click on cross tab report options, it will show moving rectangle around mouse pointer just
place it to the report header section.
As we click on header section, it

will lead to the figure

33.

,;rr.rlt, i!iallj;*1*1s1sr:,tt{*idr*ti r.lunr$ ird. iEmhwflred


Ti:* x*!E!,iid i*ld!'/Sr* !H tdlrB
*i$cn(h<a !'rr i.:!r'

$dd

.
j

_.... .
ls lhE,iii$riM xh* reiirtti r;r14!
Bill lP dr:pl.Eu ,fl thE .dB df th! g< (a

!!.t 6* /,lrs ltt${J

rr@r-l!E
AYiil..Hs

tuldii

i:akmn$

*.

'i:; li&tilri**,((drre!-linFt

} 5!ryi.ofti61 lrDi.li[]:r
Ltsllnh;
= * .aeilr6.r^Ninr.
,

Its*Trl,nt-Pradu(

*iqi.

a !l

,:
1..,1

3i{1..!l

r .. _

t.-4,/. trr,",-

lsmniiYr,

,i q'.g{$,a4r^

:r:t.l

'1:::r.:.: .1.t_ -.

Fid$r:

I
I

:.ii
I

]-

. ....... ld

t,..,--les

ls. i

Figure 33

Asperthefigure,moveCustomeP

t6 of l8

namefieldtotheRowssection,Product namewewanttoshow

814l20l4l:56 PM

http://www'codeproJ ect.com/.Arucles/ I oozv l/ \rslrr aLtr-4-rEPUr r-uDr' "

Generate a Report using Crystal Reports in Visual Studio 2010 - C"'.

to show pnoduct total so move it to the


in figure 31.
summarized fields. That's lt. Just run the report and you can see the output as shown
as a column so move it to the columns fields, and we want

It's as simple as that. If you have any queries regarding any type of the above mentioned reports,
please let me know by way of comments. I will try my level best to fulfill yoLlr request.
Let's enjoy reportingl

Article Source: DotNet Siufi

;r'ir-,

-,:":

This article, along with any associated source code and files, is licensed under The Code Proiect 01:en
Lleensr (CPOL)

Tarun Dudhatra
Software Developer Working in
Ahmedabad, Gujarat, India

lndia;S

I am working as a Software Engineer in Ahmedabad, Gujral India'

I have 6+ Years of Experience in Microsoft Technology

Like Asp.Net 2.o,Asp.Net 3 o,Asp'Net

4.0,
C#, Javascrlpt, Crystal Reports, JQuery etc.

Find out more

on;

Puhlish Artic!e

Follow on

!ix'lln'Lti
;S

l\'

ir?itier

Article Top

Comments and Discussions


You must Sign In to use this message board'
ffi&lrki

Search this forum

'r

'l:ll! l"!:p:

Normal

Perpaqe

2s

ffi$i;i,ffi

First Prev

Next

mostafataha

25-Feb-L4 20148

t*

Crysta! Report Version Error

SyedSaiiadHasan

2o-Jan-14 19:59

Menrbe.3s45689?

20-Dee-13 19:22

sri-kantho526

reports

Useful p*st

xp Reporting engine"..

18

Noise Medium Layout

Crystal repott and asp.net

'

of

l"!fd

r",+ Crysta!

17

1!-:-:l:c

$. jon-80

3-Dec-13 3:30

24-Nov-13 20:01

81412014 1:56 PM

Generate a Report usrng Crystal Repods in Visual Studro 2010 - C.:.

Hew and where in the code can


nataTable proErarnnratica!!y

ereate the

ht@://www.codepro.lect.con Arttcles/ I 6629 I/Uenerate-a-report-us1...

$p renu.iitkgp

15-Nov-13 2:53

sazzadST

27-Oct-13 0:36

bijumonjoseph

*f

Member 9115775

30-Sep-13 5:49

'

s";"nus

26-5ep-13 5:49

Bijay Kant Salotry

gcod job

Member 1O2U7O1

3-Sep-13 17:20

Will individual users need .rystal report

Member 10248199

3-Sep-l3 1L39

Litrle help

$f

jonisopara

My vote of 5

manish14982

30-Aug-13 2:30

$y. crystal report in windows applications

rakeshojha12345

28-Aug-13 5:49

d+ crystal reFort

rakeshojha1234S

28-Aug-13 5:49

Member 10212959

durgeshj

kumaruasupalli

capFranc

Could not find $t&red pr&(edure getAll0rders'

4t

Ho$E

{an we publistl crystal report


ayrd caltr frorn ccde.

appiicati*n

**

FaIy

*,+--.

{$ w*b

Trying to relate my eode to your hlog,


Thank

wd

lEr

y*u

v+te of

R*garding ts erystal report nst $how on san

Br

,i Myvate*f 5
' ExpNanat!cn
ri

15-Oct-13 22:54

My r/*te of 5

''

21-Sep-13 10:06

31-Aug-13

2t23

1s-Aug-13 21:48

30-Jul-13 0:48
25-Jul-13 19:13
23-Jul-13 3:20

th

{*

danmot a(cess xsd

(d

Thankc

mudsshir alam

3-Jul-13 2:46

S.

Wah Tarqrn h,hai Mast Superb TutorlaE tar


EeEieters.,. Thanx For Suefu Explan*tEon."

pabiswain

2-Jul-13 5:50

clean 8r underst&nd

utiz.t

Last Visie

31-Dec-99

General

file

18:00

,' News r

:;, chancnkaj

8-Jul-13 8:27

Ll-Jun-13 15:37

t 23456

Last Update:7-Apr14 15:55

Suggestion

Question

4S'

erg i;

Answer

.g{}

Joke

S nant

Next"

{? admin

ijse Ctrl+Left/Right to switch messages, Ctrl+UplDown to switch threads, Ctrl+Shift+Left/Right to switch pages.
frermalin;( | y',Cve'li$e I Frivn.ri I Mobile
Web03 I 2.8.140406.1 | Last Updated 8 Jun 2011

l8 of

18

Layout fixed I fhi.l

Arti.le Copyright 2011 by Tarun Dudhatra


Codei'rciied \999-2014

Everything else Copyright O

814120141:56 PM

Вам также может понравиться