Beruflich Dokumente
Kultur Dokumente
INTRODUCTION
ASP 2.0 using c# or VB.net
Database SQL Server, Xm
!t is use" #or $eb "eveo%ment
.Net Architecture
ASP.&et $eb A%%ication B'L (in"o$s A%%ication
'L)
*S
B'L Base cass anguage
'L) 'ommon Language )untime
*S *%erating S+stem
CLR
!t is an environment $,ic, manages t,e e-ecution o# co"ing. !t manages.-
/emor+ management
0arbage coection
1o su%%ort muti%e anguage
2&ote. "i##erence b3$ 'L) n 4V/ is t,at 4V/ on+ su%%ort singe anguage i.e. 5ava6
BCL
'oection o# stan"ar" cass or common cass $,ic, $e can use .net su%%orte" anguage
7.g. - in VB.&et $e use 8integer9 n in c# $e use 8int9 but $e can use 8int1:9, 8int;29 in
bot,.
&ote. ASP.net it is 5ust a tec,noog+ t,at runs on server $it, some anguage.
(e must ,ave common anguage s%eci#ication #or com%ier to run .net.
Why .Net?
Po$er#u
)eusabiit+
<or $eb a%%ication not #or "es=to%
- 2 -
!n $eb "eveo%ment a%%ication run on server. At cient si"e t,ere is sim%e >tm
%age $,ic, is un"erstan" b+ a bro$ser
Server in .net case is /icroso#t2running n "eveo%ing environment6
.net is not %at#orm in"e%en"ent so $e must ,ave /icroso#t *S on t,e server an"
an+t,ing on cient co? cient on+ ,ave >1/L %age
.Net Framework
'onnection o# toos, tec,noog+ n anguage $,ic, $or= toget,er to communicate
on muti%e %at#orm.
1o run .net a%%ication $e must ,ave .net #rame$or=
<rame$or= is ma"e in Per anguage.
Versio o! .et Framework
1.0 2visua stu"io 20006 beta or testing version
1.1 2visua stu"io 200;6 1@3A30;
2.0 2visua stu"io 20006 @31130B
!n 1.1 $e cover A anguages
Vb.net
'#
'CC.net
4scri%t.net
(e a""e" one more anguage in 2.0
4#
!# $e use B'L t,en t,ere is no "i##erence in t,ese anguages
(e can use muti%e anguages in an a%%ication
Com"i#atio o! .et a""#icatio
Di##erent com%ier
VB.net '1
'# '2 /S!L 4!1 &ative co"e
- ; -
4# ';
/S!L /icroso#t !nterme"iate Language 2m3c in"e%en"ent6
(e must ,ave 4!12 5ust in time6 com%ier at server $,ic, ma=e native co"e $,ic,
is m3c "e%en"ent n 'PD s%eci#ic
A$%ata&es o! 'IT(
4itna co"e c,a,i+e utna ,i com%ie =arte ,ai
7= baar native co"e banana =e baa" "ubara na,i banate
Ty"es o! 'IT(
P)7
7'>&*
&*)/AL
Com"i#atio mo$es i A)*.Net +.,
!n %ace com%iation 2b+ "e#aut6
Singe #ie com%ier at run time in $,ic, c,anges ,as been "one.
Dse" on t,e sites $,ere c,anges are "one reguar+
*ne "isa"vantage o# t,is is t,at $e nee" source co"e6
Site %re com%iation
!t use com%ier name as 8ASPnetEcom%ier9.
!t ma=es com%ii?ation #ie #or eac, #ie starting $it, 8a%%E$eb9 an" a#ter t,at
An+ ran"om generate" name i=e
abc ----- a%%E$ebi5,gt
-+? ----- a%%E$ebg#"#
!t ,as better %er#ormance
!t is #ast
A"v F &o source co"e reGuire"
Disa"vantage F even singe c,ange reGuire #u com%iation o# site
Re-uiremets !or A)*.Net
Server
!!S 2!nternet in#ormation service6 it is use" $it, 1.1 version
!t is not oa"e" on XP-,ome e"ition
(e can oa" it t,roug,
'ontro %ane --- a"" remove #ies--- $in"o$s com%onents
1o c,ange ,ome "irector+
'ontro %ane --- a"m toos --- !!S --- 'S ---$eb sites--- "e#aut $eb site
2)ig,t cic=6--- Pro%erties --- ,ome "irector+
- A -
2B+ "e#aut 8c.Hnet%ubH$$$root96
1o c,ec= $eat,er server is running or not
'ontro %ane --- a"m toos --- !!S --- 'S ---$eb sites--- "e#aut $eb site
2)ig,t cic=6---start3sto%. !# start n sto% is $or=ing !!S is running
(eb Server incu"e" in version 2.0
!t can run on XP-,ome e"ition
XP %ro#essiona $it, service %ac= 23
200; server $it, service %ac= 13
(in 2000 %ro#essiona service %ac= A
Visua stu"io 200B
First a""#icatio
<ie ne$ $ebsite ASP.&et $eb site
Location 2s%eci#+ server6 #ie s+stem 2$eb server6
>11P 2!!S6
Language Visua basic
'#
./tesio
.as%- "esigning or %resentation
.as%-.v" co"e #ie 2VB6
.as%-.cs co"e #ie 2'#6
'once%t o# Partia cass is intro"uce" in ver 2.0 $,ic, means $e can "ivi"e t,e
cass into number o# %arts. Bene#it o# t,is s+stem co"e2use" b+ s+stem6 can be
store in one %artia cass n "eveo%er co"e in anot,er.
(e can in,erit on+ one cass not muti%e in,eritance in .net
(e "i##erciate met,o", names%ace, %ro%ert+, cass b+ t,ere s+mbo
I J names%ace
; bo-es cass
Pin= bo- met,o" etc
Bi5ai event
>an" %ro%ert+
&ames%ace is coection o# casses it ma+ be neste"
- B -
A %roce"ures $,ic, ,ave ,an"es in t,e en" are events.
Page oa" event is #ire" #irst $it,out even caing t,is event. !t ,as to %arameters
1
st
#or re#erence an" 2
n"
#or manage event "ata
(in"o$s reGuire"
Soution e-%orer
1oobo-
>1/L 'ontro 2bac=groun" com%atibiit+6
)un on cient si"e an" are bro$ser "e%en"ent
(eb Server contro
)un on server si"e an" are bro$ser in"e%en"ent
Pro%ert+ $in"o$2#A6
1$o t+%es o# a+out
0ri" a+out 2avaiabe in ver 1.16
<o$ a+out 2avaiabe in bot, version6
A"vantages $e $or= as note%a", %age $i be ig,t
(eig,te" "ue to ess abes
'tr C s%ace #or inteigence ,e%.
Di##erence b3$ %ro%ert+ n variabe is t,at %ro%ert+ can be rea" on+, $rite on+,
$e vai"ation n c,ec=s can be use" but $it, variabes t,ese r not %ossibe.
*ro&ram 0(
Dis%a+ current "ate K time in abe
Sub Page_load
Label1.text = datetime.now
End sub
!n c#
Void page_load ()
{
Label1.text = datetime.now.toString();
else
{
n*otal -=n4nt;
n4ntLL;
Seection
Statements
Sele$t 4ase n
4ase P
'sg#ox (RSeroR)
D Visual #asi$ .(E* exits
D t&e Sele$t at
D t&e end o" a 4ase.
4ase 1
'sg#ox (R5neR)
4ase ,
'sg#ox (R*woR)
4ase Else
'sg#ox (R2e"aultR)
End Sele$t
swit$&(n)
{
$ase P@
4onsole.AriteLine(RSeroR);
brea%;
$ase 1@
4onsole.AriteLine(R5neR);
brea%;
$ase ,@
4onsole.AriteLine(R*woR);
brea%;
de"ault@
4onsole.AriteLine(ROR);
brea%;
<*) Loo%s
3or n = 1 *o 1P
'sg#ox(R*&e number is R I n)
(ext
3or Ea$& prop !n ob6
prop = 0,
(ext prop
"or (int i = 1; i ;= 1P; i-
-)
4onsole.AriteLine(
R*&e number is {PR/
i);
"orea$&(prop $urrent in ob6)
{
$urrent=0,;
>i"ing
Base 'ass
/embers
Publi$ 4lass #ase4ls
D *&e element to be s&adowed
Publi$ S >s !nteger = 1PP
publi$ Sub *est()
S7stem.4onsole.AriteLine( _
R*est in #ase4lsR)
publi$ $lass #ase4ls
{
?? *&e element to be
&idden
publi$ int S = 1PP;
publi$ )oid *est()
- 1B -
End Sub
End 4lass
Publi$ 4lass 2er)4ls
!n&erits #ase4ls
D *&e s&adowing element.
Publi$ S&adows S >s String =
RER
publi$ S&adows Sub *est()
S7stem.4onsole.AriteLine( _
R*est in 2er)4lsR)
End Sub
End 4lass
Publi$ 4lass Bse4lasses
D 2er)4ls widens to #ase4ls.
2im #5b6 >s #ase4ls =
(ew 2er)4ls()
D >$$ess t&roug& deri)ed
D $lass.
2im 25b6 >s 2er)4ls =
(ew 2er)4ls()
Publi$ Sub S&owS()
S7stem.4onsole.AriteLine( _
R>$$essed t&roug& base RI_
R$lass@ R I #5b6.S)
S7stem.4onsole.AriteLine(_
R>$$essed t&roug& deri)ed RI_
R$lass@ R I 25b6.S)
#5b6.*est()
25b6.*est()
End Sub
End 4lass
{
S7stem.4onsole.AriteLine(
R*est in #ase4lsR);
(>!L7
Loo%s
D *est at start o" loop
A&ile n ; 1PP .
D Same as n = n - 1.
n -= 1
End A&ile D
w&ile (n ; 1PP)
n--;
- 1: -
Parameter
Passing b+
Vaue
D *&e argument T is
Dpassed b7 )alue.
Publi$ Sub >#4( _
#7Val 7 >s Long)
D!" >#4 $&anges 7/ t&e
D $&anges do not a""e$t x.
End Sub
>#4(x) D 4all t&e pro$edure.
D Tou $an "or$e parameters to
D be passed b7 )alue/
D regardless o" &ow
D t&e7 are de$lared/
D b7 en$losing
D t&e parameters in
D extra parent&eses.
>#4((x))
?E (ote t&at t&ere is
no wa7 to pass re"eren$e
t7pes (ob6e$ts) stri$tl7
b7 )alue. Tou $an $&oose
to eit&er pass t&e re"eren$e
(essentiall7 a pointer)/ or
a re"eren$e to t&e re"eren$e
(a pointer to a pointer).E?
?? *&e met&od@
)oid >#4(int x)
{
...
- 1@ -
"inall7
{
S7stem.4onsole.AriteLine(
Rexe$uting "inall7
blo$%R);
Set an
*b5ect
)e#erence
to &ot,ing
o = (ot&ing o = null;
!nitiai?ing
Vaue 1+%es
2im dt as (ew S7stem.2ate*ime( _
,PP1/ 0/ 1,/ ,,/ 1W/ 0X/ Y00)
S7stem.2ate*ime dt =
new S7stem.2ate*ime(
,PP1/ 0/ 1,/ ,,/ 1W/
0X/ Y00);
New Features o! 1oth #a&ua&es i +,,3 %ersio
VB.&71 '#
Visua Basic 200B ,as man+ ne$ an" im%rove"
anguage #eatures -- suc, as in,eritance,
inter#aces, overri"ing, s,are" members, an"
overoa"ing -- t,at ma=e it a %o$er#u ob5ect-
oriente" %rogramming anguage. As a Visua
Basic "eveo%er, +ou can no$ create
mutit,rea"e", scaabe a%%ications using
e-%icit mutit,rea"ing. 1,is anguage ,as
#oo$ing ne$ #eatures,
1. 4ontinue Statement, $,ic,
imme"iate+ s=i%s to t,e ne-t iteration
o# a 2o, 3or, or A&ile oo%.
2. !s(ot o%erator, $,ic, +ou can avoi"
(it, t,e reease o# Visua Stu"io 200B,
t,e '# anguage ,as been u%"ate" to
version 2.0. 1,is anguage ,as #oo$ing
ne$ #eatures.
1. 4eerics ty"es are a""e" to t,e
anguage to enabe %rogrammers
to ac,ieve a ,ig, eve o# co"e
reuse an" en,ance" %er#ormance
#or coection casses. 0eneric
t+%es can "i##er on+ b+ arit+.
Parameters can aso be #orce" to
be s%eci#ic t+%es.
- 1N -
using t,e (ot an" !s o%erators in an
a$=$ar" or"er.
;. Bsing...End. Bsing statement boc=
ensures "is%osa o# a s+stem resource
$,en +our co"e eaves t,e boc= #or
an+ reason.
0. Publi$ Sub setbigbold( _
1. #7Val $ >s 4ontrol)
W. Bsing n" >s (ew _
Q. S7stem.2rawing.3ont(R>rialR/_
Y. 1,.P3/ 3ontSt7le.#old)
X. $.3ont = n"
1P. $.*ext = R*&is isR I_
11. R1,Lpoint >rial boldR
1,. End Bsing
End Sub
1;. ./"#icit 5ero Lower Bou$ o a
Array, Visua Basic no$ %ermits an
arra+ "ecaration to s%eci#+ t,e o$er
boun" 206 o# eac, "imension aong $it,
t,e u%%er boun".
1A. Usi&e$ Ty"es, Visua Basic no$
su%%orts unsigne" integer "ata t+%es
2BS&ort, B!nteger, an" BLong6 as $e
as t,e signe" t+%e S#7te.
1B. O"erator O%er#oa$i&, Visua Basic
no$ ao$s +ou to "e#ine a stan"ar"
o%erator 2suc, as -, I, (ot, or 'od6 on a
cass or structure +ou ,ave "e#ine".
1:. *artia# Ty"es, to se%arate generate"
co"e #rom +our aut,ore" co"e into
se%arate source #ies.
1@. Visua Basic no$ su%%orts t+%e
%arameters on generic casses,
structures, inter#aces, %roce"ures, an"
"eegates. A corres%on"ing t+%e
argument s%eci#ies at com%iation time
t,e "ata t+%e o# one o# t,e eements in
t,e generic t+%e.
1N. Custom .%ets. Qou can "ecare
custom events b+ using t,e 'ustom
=e+$or" as a mo"i#ier #or t,e E)ent
statement. !n a custom event, +ou
s%eci#+ e-act+ $,at ,a%%ens $,en
co"e a""s or removes an event ,an"er
to or #rom t,e event, or $,en co"e
raises t,e event.
1O. Com"i#er Checki& O"tios, 1,e
2. Iterators ma=e it easier to "ictate
,o$ a #or eac, oo% $i iterate
over a coectionLs contents.
+. ?? !terator Example
0. publi$ $lass (um4&ar
1. {
W. string9: sa(um = {
Q. R5neR/ R*woR/ R*&reeR/
Y. R3ourR/ R3i)eR/ RSixR/
X. RSe)enR/ REig&tR/ R(ineR/
1P. RSeroR;
11. publi$
1,.
S7stem.4olle$tions.!Enumerat
or
1+. 8etEnumerator()
10. {
11. "orea$& (string num in
sa(um)
1W. 7ield return num;
1Q.
1Y.
1X. ?? 4reate an instan$e o"
,P. ?? t&e $olle$tion $lass
,1. (um4&ar o(um4&ar = new
(um4&ar();
,,. ?? !terate t&roug& it wit&
"orea$&
,+. "orea$& (string num in
o(um4&ar)
,0. 4onsole.AriteLine(num);
2B. Partial t+%e "e#initions ao$ a
singe t+%e, suc, as a cass, to be
s%it into muti%e #ies. 1,e Visua
Stu"io "esigner uses t,is #eature to
se%arate its generate" co"e #rom
user co"e.
2:. Nullable t+%es ao$ a variabe
to contain a vaue t,at is
un"e#ine".
2@. Anonymous 6etho$ is no$
%ossibe to %ass a boc= o# co"e as
a %arameter. An+$,ere a "eegate
is e-%ecte", a co"e boc= can be
use" instea". 1,ere is no nee" to
"e#ine a ne$ met,o".
,Y. button1.4li$% -=
,X. delegate
{ 'essage#ox.S&ow(
R4li$%KR) ;
;0. . 1,e ames"ace a#ias -ua#i!ier
2@@6 %rovi"es more contro over
- 1O -
3no$arn an" 3$arnaserror o%tions
%rovi"e more contro over ,o$
$arnings are ,an"e". 7ac, one o# t,ese
com%ier o%tions no$ ta=es a ist o#
$arning !Ds as an o%tiona %arameter,
to s%eci#+ to $,ic, $arnings t,e o%tion
a%%ies.
20. 1,ere are eig,t ne$ comman"-ine
com"i#er o"tios(
a. 1,e 7co$e"a&e o%tion s%eci#ies
$,ic, co"e%age to use $,en
o%ening source #ies.
b. 1,e 7$oc o%tion generates an
X/L "ocumentation #ie base"
on comments $it,in +our co"e.
c. 1,e 7errorre"ort o%tion
%rovi"es a convenient $a+ to
re%ort a Visua Basic interna
com%ier error to /icroso#t.
". 1,e 7!i#ea#i& o%tion s%eci#ies
t,e si?e o# sections in +our
out%ut #ie.
e. 1,e 7oco!i& o%tion causes t,e
com%ier to ignore t,e Vbc.rsp
#ie.
#. 1,e 7ost$#i1 o%tion %revents
t,e im%ort o# mscorlib.dll,
$,ic, "e#ines t,e entire S+stem
names%ace.
g. 1,e 7"#at!orm o%tion s%eci#ies
t,e %rocessor to be targete" b+
t,e out%ut #ie, in t,ose
situations $,ere it is necessar+
to e-%icit+ s%eci#+ it.
,. 1,e 7ui!y o%tion su%%resses
$arnings resuting #rom a
mismatc, bet$een t,e versions
o# "irect+ an" in"irect+
re#erence" assembies.
accessing names%ace members.
1,e goba @@ aias ao$s to
access t,e root names%ace t,at
ma+ be ,i""en b+ an entit+ in +our
co"e.
;1. Static c#asses are a sa#e an"
convenient $a+ o# "ecaring a
cass containing static met,o"s
t,at cannot be instantiate". !n '#
v1.2 +ou $ou" ,ave "e#ine" t,e
cass constructor as %rivate to
%revent t,e cass being
instantiate".
;2. N. 1,ere are eig,t ne$ com"i#er
o"tios.
a. 7#a&%ersio o%tion. 'an
be use" to s%eci#+
com%atibiit+ $it, a
s%eci#ic version o# t,e
anguage.
b. 7"#at!orm o%tion. 7nabes
+ou to target !P< 2!A:A or
!tanium6 an" A/D:A
arc,itectures.
c. 8"ra&ma $arning. Dse" to
"isabe an" enabe
in"ivi"ua $arnings in
co"e.
". 7#ikresource o%tion.
'ontains a""itiona
o%tions.
e. 7errorre"ort o%tion. 'an
be use" to re%ort interna
com%ier errors to
/icroso#t over t,e
!nternet.
#. 7keycotaier an"
7key!i#e. Su%%ort
s%eci#+ing cr+%togra%,ic
=e+s.
- 20 -
VALIDATION AND C9.C2)
Vai"ations are %rovi"e" b+ /icroso#t in Vb.net
)un on cient site.
!n as% 4avaScri%t $i not run i# cient site "onSt ,ave 4avaScri%t
!n .net i# not 5scri%t at cient t,en t,e+ run on server.
Ty"es o! %a#i$ators
1,ere are : t+%es o# vai"ators
)eGuire" #ie" vai"ator 2 #or em%t+ c,ec=6.
'om%are vai"ator. (e can com%are
contros 2i=e %ass$or" n con#irm %ass$or"6
vaue 2age must be greater t,en 1N6
"ata t+%e c,ec= 2saar+ must be no.6
)ange vai"ator
)eguar e-%ression vai"ator
Pre "e#ine #ormat 2vai" emai a""ress6
- 21 -
'ustom vai"ator
Vai"ation summar+
(eb.D!.Vai"ation.5s is t,e #ie name in $,ic, 5scri%t o# a t,ese vai"ator are
avaiabe.
(e not abe to associate contros $it, vai"ators in ASP.&et 1.1 but can "o t,is in
2.0 7.g. 8username n %ass9 an" searc, is c,ec= b+ "i##erent button.
Re-uire$ !ie#$ %a#i$atio "ro"erties
contro1oVai"ate name o# te-tbo- to c,ec=
1e-t message
Com"are %a#i$atio "ro"erties
contro1oVai"ate name o# #irst te-tbo- to c,ec=
1e-t message
contro1oVai"ate name o# secon" te-tbo- to c,ec=
<or vaue c,ec=
contro1oVai"ate name o# te-tbo- to c,ec=
vaue1o'om%are vaue to c,ec=
o%erator greater, ess, eGua etc
t+%e integer
1e-t message
<or saar+ must be number c,ec=
contro1oVai"ate name o# te-tbo- to c,ec=
o%erator Data t+%e c,ec=
t+%e integer
1e-t message
<or range c,ec=
contro1oVai"ate name o# te-tbo- to c,ec=
minimumVaue vaue
ma-imumVaue vaue
1e-t message
<or vai" emai a""ress c,ec=
contro1oVai"ate name o# te-tbo- to c,ec=
Vai"ation7-%ression Po%u% $in"o$
1e-t message
- 22 -
Va#i$atio summary
7= 5ag,a sare error n asteris= sign in #ront o# error
1e-t %ro%ert+ vaue "is%a+ on vai"ator an" error message "is%a+ on t,e vai"ation
summar+.
1e-t T
error/essage 7m%no em%t+
1o run vai"ation summar+ $e nee" a button
1o ma=e %o%u% $in"o$ go to vai"ation summar+ %ro%ert+
S,o$/essageBo- true
S,o$ Summar+ #ase
A""ition %ro%erties in version 2.0
set t,e causes vai"ation %ro%ert+ to #ase to "isabe t,e vai"ation o# button
vai"ation grou% %ro%ert+ o# vai"ator 2te-tbo-, vai"ationSummar+ n o# button6
o Vai"ation0rou% a
%ro%ert+ o# vai"ator
o Set#ocuson7rror to go "irect+ to t,e error %oint s=i% correct %aces.
A"" more t,an one %age in $ebsite 2'ic= on $ebsite a"" ne$ item $eb#orm6
1o /a=e startu% %age 2go to soution e-%orer rig,t cic= on %age set as start
%age6.
1o go to ne$ %age $e ,ave ; met,o"s
o )es%onse.re"irect26
o Server.trans#er26
o Server.e-ecute26
1o go to ne-t %age b+ button
o )es%onse.re"irect28"e#aut.as%-96
1o go to ne-t %age b+ ,+%erin= %ro%erties
o 1e-t ne-t
o &avigate D)L "e#aut.as%-
(,en $e $ant to move to ne-t %age $it,out submitting t,e current %age $e use
,+%erin=.
Basic Cotro#s i .et
c,ec=bo-
$&e$%box1_$&e$%ed $&anged e)ent
{
!"($&e$%box.$&e$%ed == true)
{
- 2; -
*extbox1."ont.bold = true;
Else
{
*extbox1."ont.bold = "alse;
o $eb server contro ,as %ro%ert+
autoPostBac= to ma=e t,e %age submit $,en t,ere vaue c,anges
co? a $eb server contro acce%t vaue a#ter cic=ing
on button.
)a"io button
o Pro%ert+ 0rou%&ame to mention t,e grou%.
o 1,e+ ,ave on+ seecte" $,enever $e cic= on t,em not ic= c,ec=bo-.
radiobutton_$&e$%ed $&anged e)ent
{
*extbox1."ore$olor = $olor.red
/* For collection
We must have namespace
Using System.collection
!ollection is data structure to store items
"rraylist
array of ob#ects $hich increase its si%e dynamically.
by default has si%e e&ual to ' characters.
*/
>rra7list arr = new >rra7List();
arr.add(Zab$[);
arr.add(Zx7=);
$&e$%boxlist1.dataSour$e = arr;
$&e$%boxlist1.data#ind();
// both these methods $or( together
4&e$%boxlist1.items9P:.enabled = "alse;
#utton1_$li$%
{
3or(int+, i=P;i;$&e$%boxlist1.items.$ount; i--)
{
!"($&e$%boxlist1.item9i:.sele$ted==true)
*extbox1.text-=$&e$%boxlist1.item9i:.
text -[Fn[;
1e-tbo- %ro%ert+
1e-tmo"e muti%e ine 2to "is%a+ "ata in muti%e ine6
1o store "i##erent vaue in c,ec=bo- at be,in"
2,i""en name vaue, "is%a+ name te-t6
1o a"" vaue #ie"
- 2B -
',ec=bo-ist1.items.a""2ne$ ist!tem28aa9,91966R
1o retrieve vaue
',ec=bo-ist1.itemsUiV.vaueR
DATABA). 9ANDLIN4
Di##erence bet$een /sAccess an" SQL
!n orace K SQL t,ere are triggers, %roce"ure, #unctions, cursor genera+ =no$ as
com%ie ob5ects $,ic, are store in "atabase an" e-ecute" in "atabase on+ "ue to
$,ic, tra##ic $i not so$ "o$n.
Database server an" a%%ication server are t$o "i##erent t,ings.
Store %roce"ure once e-ecute", ne-t time t,e %roce"ure $i be #aster t,an be#ore.
Less s%ace in access.
Less securit+ in access.
*race is OO.OW use" b+ t,e t,ose com%anies $,ic, ,ave o$n server.
!n (eb "eveo%ment OOW $e use SQL.
- 2: -
ADO.Net 2ActiveX Data *b5ect6
!t is an environment $,ic, is "esign b+ /icroso#t #or "atabase ,an"ing.
1$o main com%onents
o X/L 2 it is incense #ree, %at#orm in"e%en"ent an" t,e #astest $a+ o# "ata
trans#er 6.
o Disconnecte" a%%roac, 2"ata is co%ie" at a%%ication server an" t,e connect
$it, t,e "atabase server is "isconnecte" so t,at origina "ata $i remain
untouc,e"6.
!t "esign $,ie ,aving $eb a%%ication in min".
Data1ase coecti%ity
1,ere are A $a+s o# connectivit+ $it, "atabase
o *DB' 2*%en DataBase 'onnectivit+6 Used to connect to each n
o *L7DB 2*b5ect Lin=ing K 7mbe""ing6 every server
o SQL'ient 2s%eci#ica+ use" $it, /s SQL server. !t is incu"e" in .net6
o *)A'L7'ient 2s%eci#ica+ use" $it, *race server. !t is incu"e" in .net6
Better performance and !ompatibility
1$o main #ies are t,ere
o .m"# 2/icroso#t "atabase #ie6
o ."# 2 og "atabase #ie6
1o create "atabase
o Vie$ server e-%orer
o !n ast t,ere is 8server9 to =no$ t,e server name
o Data connection2rig,t cic=6 create ne$ SQL server DB
o /ention t,ese #ie"s
Server name sac
Dse SQL server aut,entication
Dsername 8sa9 2"e#aut6
&e$ "atabase name "bem%o+ee
o &o$ t,is "bem%o+ee $i be a""e" in "ata connection
o Sac."bem%o+ee tabe2rig,t cic=6 a"" ne$ tabe
o /ention coumn name an" "ata t+%e as
7no int
7name varc,ar2B06
- 2@ -
7a""ress varc,ar2B06
7sa int
Di##erence bet$een varc,ar an" nvarc,ar is t,at varc,ar uses AS'!! an" nvarc,ar
uses Dnico"e.
(eb.con#ig #ie
o !t is use" to store connection string. !t is to mani%uate it i# server name, ui"
c,anges instea" o# going to eac, n ever+ %age $e 5ust c,ange it in $eb.con#ig.
o &on com%ie #ie $,ere as mo"ue ,as to com%ie
o X/L base", 'ase sensitive
o Secure in version 2.0 2$e cant vie$ t,e #ie $it,out co"ing6
o !nteigence ,e% is %rovi"e" in version 2.0
o !t can be muti%e in singe %ro5ect but mac,ine.con#ig is singe in one %ro5ect.
o !t is #or %ro5ect con#iguration e.g. securit+ setting, session setting etc
o 1o a"" $eb.con#ig
(ebsite a"" ne$ item $eb con# #ie
o A"" connection string in t,is #ie
Xconnection stringY
Xa"" nameZ9nonu9 connectionStringZ9serverZsacR "atabaseZ"bem%o+eeR
(ey
ui"ZsaR %$"Za"min93Y
)t is used if u have
mentioned pass$ord
X3connection stringY
o Server name in connection string is not com%usor+ i# ur server is same
s+stem $,ere a%%ication is running.
o !n 1.0 $e a"" connection string in Xa%%settingsY tag
7g. Xa"" =e+Z9cs9 vaueZ9"atabaseZ"bem%Rui"Zsa9Y
An" 7-cess t,is as con#igurationSetting.A%%SettingsU8cs9V
Di##erence bet$een
o >as, stores =e+ as $e as vaue
o Arra+ stores on+ vaue
(e s,ou" a""
Bsing S7stem.data.S\L4lient;
4lass_de"ault
{
S\L4onne$tion $on = new S\L4onne$tion();
// S*+!onnection class is used to establish connection
Page_load
- 2N -
{
*&is.smart(a)igation = true;
// in c, $e use -this. and in VB./et $e use -me.
4on.$onne$tionString =
4on"iguration'anager.4onne$tionString9Znonu[:.
$onne$tionString;
// !onfigurationManager is used to read connection string.
!" ($on.State ==4onne$tionState.4losed)
{
4on.open();
#utton1_$li$% // save
{
S\L$ommand $md = new sVl$ommand();
// S*+!ommand bridge bet$een data and database. Used for save4 delete4 update4
display
$md.4ommand*ext.=[!nsert into t&emp
)alues(]eno/]en/]ed]es)[;
// command5e6t is used to specify &uery or store procedure4 7eno are parameters $ith
are used at runtime
$md.$ommand=$on;
// connection established
$md.parameters.add(Z]eno[/sVldbt7pe.!nt).)alue =
$on)ert.*o!nt+,(textbox1.text);
- 2O -
// S&ldbtype is enumerator0user define datatype1
$md.parameters.add(Z]en[/sVldbt7pe.Var$&ar/ 1P).
)alue = textbox,.text;
$md.exe$ute(on\uer7();
// 86ecute/on*uery 86ecute the &uery and return the no. of data received.
$md.dispose(); // destructor
textbox1.text= get>uto().toString();
??textbox1.text = Z Z;
textbox,.text = Z Z;
textbox+.text = Z Z;
textbox0.text = Z Z;
J
J
J
U"$ate co$e
#utton,_$li$% ??update
{
S\L$ommand $md = new sVl$ommand ();
$md.$ommand*ext=[update tbemp set ename=]en/ edd =
]ed/ esal = ]es w&ere empno = ]eno[;
$md.$ommand=$on;
$md.parameters.add (Z]eno[/ sVldbt7pe.!nt).)alue =
$on)ert.*o!nt+, (textbox1.text);
$md.parameters.add (Z]en[/ sVldbt7pe.Var$&ar/ 1P).
)alue = textbox,.text;
$md.exe$ute(on\uer7 ();
$md.dispose ();
textbox1.text = Z Z;
textbox,.text = Z Z;
textbox+.text = Z Z;
textbox0.text = Z Z;
De#ete Co$e
#utton+_$li$% ??delete
{
S\L$ommand $md = new sVl$ommand();
$md.$ommand*ext=[delete "rom tbemp w&ere empno=]eno[;
$md.$ommand=$on;
$md.parameters.add(Z]eno[/sVldbt7pe.!nt).)alue =
- ;0 -
$on)ert.*o!nt+,(textbox1.text);
$md.parameters.add(Z]en[/sVldbt7pe.Var$&ar/ 1P).
)alue =textbox,.text;
$md.exe$ute(on\uer7();
$md.dispose();
textbox1.text = Z Z;
textbox,.text = Z Z;
textbox+.text = Z Z;
textbox0.text = Z Z;
Dis"#ay co$e
#utton0_$li$%
{
S\L$ommand $md = new sVl$ommand();
$md.$ommand*ext =[sele$t E "rom tbemp[;
$md.$onne$tion = $on;
S\L2ataCeader dr;
/*
S*+9ata:eader is used to vie$ data4
)t is read only.
For$ard only 0 only go in for$ard direction1
)t is the fastest $ay of data retrieval.
Se&uential read.
/o need of -ne$. operator.
)t is segantal class used to pass reference #ust li(e abstract class.
We should close it after using it co% other$ise $e can3t use it again li(e static
method it has only one memory.
*/
2r = $md.Exe$uteCeader ();
// 86ecute:eader #ust e6ecute the &uery n store the data in variable0#ust for display1
Listbox1.data*ext3ield =[ename[;
// 9ata5e6tField display the data in listbo6
Listbox1.dataValue3ield =[empno[;
// value at the bac( side of listbo6 0not visible1
- ;1 -
Listbox1.2ataSour$e = dr;
Listbox1.2ata#ind();
2r.$lose();
$md.dispose();
)TOR. *ROC.DUR.)
1,e+ can %ass ma-imum 102A numbers o# %arameters
1,ere are ; t+%es o# %arameters
o !n%ut 25ust to %ass t,e vaue6
o *ut%ut 25ust to return t,e vaue6
o !n%ut3out%ut 2$e can %ass as $e as return vaue6
1,e+ can return vaue
Pre com%ie ob5ects
- ;; -
Di##erence bet$een #unction an" %roce"ure
o <unction must return vaue, %roce"ure ma+ or ma+ not return vaue
o <unction can return an+ t+%e o# "ata $,et,er arra+, integer, ob5ect etc but
%roce"ure can return on+ integer.
o <unction is use" as variabe but %roce"ure is e-ecute"
o Proce"ure is com%ie" in memor+
o Store in "atabase an" e-ecute" in "atabase an" once e-ecute comes in t,e
cac,e $,ic, ,e% it run more #aster ne-t time.
o Store %roce"ure SQL engine %ar e-ecute ,ote ,ai, #unction #irst goes to SQL
server an" t,ere t,e+ #irst com%ie n t,en e-ecute".
1o create store %roce"ure go to server e-%orer
o Sac."bem% 2"atabase6 Store %roce"ure 2)ig,t cic=6 A"" ne$ store
%roce"ure.
1,e anguage in $,ic, $e $or= is =no$ as tangent SQL or 1-SQL.
)a%e "roce$ure
4CE>*E PC54E2BCE insemp
(
]eno int/
]en )ar$&ar(1P)/
]ed )ar$&ar(1P)/
]es int
)
>S
!nsert into tbemp )alues(]eno/]en/]ed/]es)
(,en $e save t,is ')7A17 $i automatica+ c,anges to AL17) t,at means in
#uture $e can on+ ater t,is %roce"ure.
!# $e "onSt s%eci#+ t,e si?e in varc,ar t,en it $i store on+ one c,aracter.
U"$ate "roce$ure
4CE>*E PC54E2BCE updemp
(
]eno int/
]en )ar$&ar(1P)/
]ed )ar$&ar(1P)/
]es int
)
- ;A -
>S
Bpdate tbemp set ename = ]en/ eaddress = ]ed/ esal =
]es w&ere empno = ]eno
De#ete "roce$ure
4CE>*E PC54E2BCE delemp
(
]eno int
)
>S
2elete tbemp w&ere empno = ]eno.
Dis"#ay "roce$ure
4CE>*E PC54E2BCE dispemp
>S
Sele$t E "rom tbemp.
Fi$ "roce$ure
4CE>*E PC54E2BCE "indemp
(
]eno int
)
>S
Sele$t E "rom tbemp w&ere empno = ]eno
(e can store more t,an one Guer+ in one %roce"ure $,en $e "o more t,an one $or=
in a singe ste% i=e $,en $e cic= on button t,en Save n D%"ate $i run
simutaneous.
Autheticatio "roce$ure
'reate tabe 2tbuser6
o Dname varc,ar2B06
o D%ass varc,ar2B06
4CE>*E PC54E2BCE login4&e$%
(
]u )ar$&ar(1P)/
]p )ar$&ar(1P)
)
>S
2e$lare ]ap )ar$&ar(1P)
SELE4* ]ap = upass "rom tbuser w&ere uname = ]u
- ;B -
!" ]ap is null
Ceturn L1
Else
!" ]ap = ]p
Ceturn 1
Else
Ceturn L,
!# $e "onSt $rite an+t,ing in #ront o# %arameter t,en b+ "e#aut t,e+ are o# t+%e in%ut.
!# uname is not vai" t,en seect statement return nu in [a%.
&o$ instea" o# $riting comman" in #ront en" $e $rite t,ese t$o ines
o 'm".comman"1e-tZ9;rocedure name9R
o 'm".comman"1+%eZcomman"1+%e.StoreProce"ureR
'omman"1+%e tes us t,e t+%e o# comman".
1o enter "ata "irect+ to tabe rig,t cic= on t,e tabe in t,e server e-%orer
s,o$ tabe "ata.
A"" t$o t,ree accounts in t,e tabe
Design t,e #ront vie$ "esign o# ogin screen
Bsing S7stem.data.S\L4lient;
4lass_de"ault
{
S\L4onne$tion $on = new S\L4onne$tion;
Page_load
{
4on.$onne$tionString = $on"iguration'anager.
$onne$tionString9Znonu[:.$onne$tionSting;
i" ($on.state = = $onne$tionState.$losed)
{
4on.open();
Else
{
Label1.text = [L58!([;
2ataList1_4an$el4ommand(sour$e/ e)
- AA -
{
2ataList1.Edit!tem!ndex = L1;
List#ind();
2ataList1_Bpdate4ommand(sour$e/ e)
{
String title/ aut&or/ pub;
!nt+, pr$;
*itle=((textbox)(e.!tem.3ind4ontrol(Zt1[))).text;
>ut&or =((textbox)(e.!tem.3ind4ontrol(Zt,[))).text;
Pub =((textbox)(e.!tem.3ind4ontrol(Zt+[))).text;
Pr$=4on)ert.*o!nt+,(((textbox)
(e.!tem.3ind4ontrol(Zt0[))).text);
bid = 4on)ert.*o!nt+,
(2ataList1.2ata`e7s9e.!tem.!tem!ndex:);
SVl4onne$tion $on = new SVl4onne$tion();
$on.4onne$tionString = 4on"iguration'anager.
4onne$tionStrings9R$sR:.4onne$tionString;
i" ($on.State == 4onne$tionState.4losed)
{
$on.5pen();
SVl4ommand $md = new SVl4ommand();
$md.4ommand*ext = Rupdate tbboo% set boo%*itle=]title/
boo%>ut&or =]aut&or/ boo%Pub=]pub/ boo%Pri$e=]pr$ w&ere
boo%!d=]bidR;
$md.4onne$tion = $on;
$md.Parameters.>dd(RtitleR/ SVl2b*7pe.Var4&ar/ 1P).Value = title;
$md.Parameters.>dd(Raut&orR/ SVl2b*7pe.Var4&ar/ 1P).Value=aut∨
$md.Parameters.>dd(RpubR/ SVl2b*7pe.Var4&ar/ 1P).Value = pub;
$md.Parameters.>dd(Rpr$R/ SVl2b*7pe.!nt).Value = pr$;
$md.Parameters.>dd(RbidR/ SVl2b*7pe.!nt).Value = bid;
$md.Exe$ute(on\uer7();
$md.2ispose();
2ataList1.Edit!tem!ndex = L1;
List#ind();
2ataList1_4an$el4ommand(sour$e/ e)
{
2ataList1.Edit!tem!ndex = L1;
2ataList1.2ata#ind();
- AN -
:. *RODUCT) WIT9 C9.C2BO<
Pace DataList1, DataList2, Button
A"" $eb.con#ig #ie.
Bsing S7stem.2ata.SVl$lient;
Page_load
{
!"(page.isPost#a$%=="alse)
{
SVl2ata>dapter adp = new SVl2ata>dapter(Rsele$t E "rom tbboo%R/
4on"iguration'anager.4onne$tionStrings9R$sR:.4onne$tionString);
2ataSet ds = new 2ataSet();
adp.3ill(ds);
2ataList1.2ataSour$e = ds;
2ataList1.2ata#ind();
#utton_$li$%
{
String st=[[;
3or(int+, i=P; i;2ataList.item.$ount;i--;)
{
$&e$%box $=($&e$%box)(2atalist1.item9!:.3ind4ontrol(Z$b[));
i"($.$&e$%ed ==true)
st -=2ataList1.2ata`e79!:.toString() -[/[;
St = st.Substring(P/st.lengt&L1);
SVl2ata>dapter adp = new SVl2ata>dapter(Rsele$t E "rom produ$ts
w&ere produ$t !n(Z-st-[)[)/4on"iguration'anager.
4onne$tionStrings9R$sR:.4onne$tionString);
2ataSet ds = new 2ataSet();
adp.3ill(ds);
2ataList,.2ataSour$e = ds;
2ataList,.2ata#ind();
!n >1/L
;asp@2ataList1_<
;!tem*emplate<
;b<;GE)al(Zprodu$t(ame[)G<;br?<
;asp@$&e$%box !2=[$b[ text=[#u7[ runat=ser)er<
- AO -
;?!tem*emplate<
;?asp@2ataList1<
;asp@2ataList,<
;!tem*emplate<
;b<;GE)al(Zprodu$t(ame[)G<;?b<;br?<
;b<;GE)al(ZunitPri$e[)G<;?b<;br?<
;?!tem*emplate<
;?asp@2ataList1<
1o %rint out%ut on #orm $e use )es%onse.$rite28>eo (or"96
- B0 -
:. DI)*LA; ).L.CT.D DATA IN T.<TBO<
Pace "ataList #rom toobo-
A"" $eb con#ig #ie an" ma=e connection string.
Bsing S7stem.2ata.SVl$lient;
Pri)ate )oid List#ind()
{
SVl2ata>dapter adp = new SVl2ata>dapter(Rsele$t E "rom tbboo%R/
4on"iguration'anager.4onne$tionStrings9R$sR:.4onne$tionString);
2ataSet ds = new 2ataSet();
adp.3ill(ds);
2ataList1.2ataSour$e = ds;
2ataList1.2ata#ind();
Page_load
{
!"(page.isPost#a$%=="alse)
List#ind();
2ataList1_Sele$ted!ndex4&anged
{
String st;
st = Rsele$t E "rom tbboo% w&ere boo%!d=R -
2ataList1.2ata`e7s9sele$ted!ndex:.*oString();
SVl2ata>dapter adp = new SVl2ata>dapter(st/ 4on"iguration'anager.
4onne$tionStrings9R$sR:.4onne$tionString);
2ataSet ds = new 2ataSet();
adp.3ill(ds);
??*ext#ox1.*ext=ds.*ables9P:.Cows9P:
9Rboo%*itleR:.*oString();
??*ext#ox,.*ext = ds.*ables9P:.Cows9P:
9Rboo%>ut&orR:.*oString();
??*ext#ox+.*ext = ds.*ables9P:.Cows9P:
9Rboo%PubR:.*oString();
??*ext#ox0.*ext = ds.*ables9P:.Cows9P:
9Rboo%PrieR:.*oString();
// 9S is an ob#ect n is very heary so it3s not good to call it again n again. We should use
properties4 method4 variable but not ob#ects
- B1 -
2ataCowView r;
33 9ata:o$Vie$ class only accept single ro$.
r=ds.*ables9P:.2e"aultView9P:;
*ext#ox1.*ext = r9P:9Rboo%*itleR:.*oString();
*ext#ox,.*ext =r9P:9Rboo%>ut&orR:.*oString();
*ext#ox+.*ext = r9P:9Rboo%PubR:.*oString();
*ext#ox0.*ext = r9P:9Rboo%Pri$eR:.*oString();
!n >1/L
;asp@2ataList_<
;!tem*emplate<
;b<*itle@
;?b<;asp@Lin%#utton !2=RlbR *ext=D;GUE)al(Rboo%*itleR)G<D
4ommand(ame=[sele$tR runat=ser)er<
;?asp@Lin%#utton<;br ?<
;b<>ut&or@ ;?b<;GUE)al(Rboo%>ut&orR)G<;br ?<
;b<Publis&er@ ;?b<;GUE)al(Rboo%PubR)G<;br ?<
;b<Pri$e@ ;?b<;GUE)al(Rboo%Pri$eR)G<;br ?<
;?!tem*emplate<
- B2 -
:. .<*AND AND COLLA*).
Pace )e%eater #rom toobo- c,ose "ata source
Pace SGDataSource1 con#igure "ata source
!n >1/L
;&ead runat=Rser)erR<
;title<Bntitled Page;?title<
;st7le <
.ab${"ontLsi=e@larger;"ontLweig&t@bold
.x7={displa7@none;)isibilit7@&idden
;?st7le<
;s$ript language=D6a)as$riptD<
"un$tion get2ata(id)
{
)ar e;
$olor(id);
e=do$ument.getElement#7!d(DdD-id);
i"(e)
{
i"(e.st7le.displa7K=Dblo$%D)
{
e.st7le.displa7=Dblo$%D;
e.st7le.)isibilit7=D)isibleD;
else
{
e.st7le.displa7=DnoneD;
e.st7le.)isibilit7=D&iddenD;
"or()ar i=P;i;W;i--)
{
i"(i==id)
{
i--;
)ar e1=do$ument.getElement#7!d(DdD-i);
i"(e1)
{
e1.st7le.displa7=DnoneD;
e1.st7le.)isibilit7=D&iddenD;
- B; -
"un$tion $olor(id)
{
)ar e1;
e1=do$ument.getElement#7!d(D&D-id);
i"(e1)
{
e1.st7le.$olor=DblueD;
"or()ar i=P;i;W;i--)
{
i"(i==id)
{
i--;
e,=do$ument.getElement#7!d(D&D-i);
i"(e,)
{
e,.st7le.$olor=Dbla$%D;
;?s$ript<
;asp@Cepeater !2=RCepeater1R runat=Rser)erR<
;!tem*emplate<
;di) id=D&;GU2ata#inder.E)al(4ontainer/RitemindexR)G<D ondbl$li$%=
Dget2ata(;GU2ata#inder.E)al(4ontainer/RitemindexR)G<)D
$lass=Dab$D on$li$%=D$olor(;GU2ata#inder.E)al
(4ontainer/RitemindexR)G<)D <
;b<;GUE)al(Rboo%*itleR)G<;br ?<;?b<
;?di)<
;di) id=Dd;GU2ata#inder.E)al(4ontainer/RitemindexR)G<D
$lass=Dx7=D<
;b< >ut&or@;?b<;GUE)al(Rboo%>ut&orR)G<;br ?<
;b< Publis&er@;?b<;GUE)al(Rboo%PubR)G<;br ?<
;b< Pri$e@;?b<;GUE)al(Rboo%Pri$eR)G<;br ?<;br ?<
;?di)<
;?!tem*emplate<
;?asp@Cepeater<
Div is a container in $,ic, $e store "i##erent t,ings
!n St+e
o Dis%a+ . none coa%se, boc= e-%an"
0et7ementB+!" in 4avaScri%t is 5ust i=e <in"'ontro to #in" t,e contro.
- BA -
:. *A4IN4
'reate a store %roce"ure in "atabase.
(e use cursor in t,is $,ic, are
o Private area to SQL
o Store )esut o# Guer+
o !n#ormation in cursor is cae" Data set.
o 1,e cursor $,ic, stores t,e resut o# seect is cae" im%icit cursor.
'ursor ,as A ste%s.
o 'reate
o *%en
o <etc,
o 'ose
>L*EC PC54E2BCE dbo.StoredPro$edure1
(
]pagenumber int/
]pagesi=e int
)
>S
de$lare ]stre$ int
de$lare ]endre$ int
de$lare ]stpid int
de$lare ]endpid int
de$lare ]re$$ount int
set ]stre$ = ]pagenumberE]pagesi=eL]pagesi=e-1
de$lare $_prd s$roll $ursor "or
sele$t produ$t!d "rom tbprodu$t order b7 produ$t!d
open $_prd
"et$& absolute ]stre$ "rom $_prd into ]stpid
// $e use absolute co% if value is >ve it ta(e from the last.
sele$t ]re$$ount=$ount(E) "rom tbprodu$t w&ere
produ$tid < ]stpid
i" ]re$$ount ; ]pagesi=e
begin
set ]endre$ = ]stre$ - ]re$$ount
end
else
begin
- BB -
set ]endre$ = ]pagenumber E ]pagesi=e
end
"et$& absolute ]endre$ "rom $_prd into ]endpid
$lose $_prd
sele$t $ount(E) "rom tbprodu$t
sele$t produ$t(ame/ unitPri$e/ $ategor7(ame "rom tbprodu$t a/
tb$ategor7 b w&ere a.$ategor7!d = a.$ategor7!d and
produ$t!d < ]stpid and produ$t!d ;= ]endpid
De!au#t.as"/.cs
prote$ted )oid Page_Load(sender/ e)
{
i" (Page.!sPost#a$% == "alse)
{
Page#ind(1);
I 9T6L
;asp@2ataList !2=R2ataList1R runat=Rser)erR<
;!tem*emplate<
;b< (ame@ ;?b<;GUE)al(Rprodu$t(ameR)G<;br ?<
;b< Pri$e@ ;?b<;GUE)al(RunitPri$eR)G<;br ?<
;b< 4ategor7@;?b<;GUE)al(R$ategor7(ameR) G<;br ?<
;?!tem*emplate<
;?asp@2ataList<
;asp@2ataList !2=R2ataList,R runat=Rser)erR<
;!tem*emplate<
;asp@Lin%#utton !2=RlbR *ext=D;GU4ontainer.2ata!temG<D
4ommand(ame=Rsele$tR runat=Rser)erR<
;?asp@Lin%#utton<
;?!tem*emplate<
;?asp@2ataList<
- BO -
4RIDVI.W
1o "is%a+ "ata in ro$s K coumns.
(e can mani%uate "ata 2e"it, "eete, an" u%"ate6.
Auto e"it, "eete, seect
!nbuit %aging
!nbuit sorting
'oumn boun"
N tem%ates are a%%icabe
o !tem tem%ate
o >ea"er tem%ate
o <ooter tem%ate
o Seect tem%ate
o Pager tem%ate
o 7"it item tem%ate
o Aternating item tem%ate
o 7m%t+ "ata tem%ate
Pro%erties o# 0ri"Vie$
o Auto0enerateDeeteButton true
o Auto0enerate7"itButton true
o Auto0enerateSeectButton true
o Ao$Paging true
o PageSi?e 2
o PagerSetting
/o"e &umeric3&e-tPrev<irstLast
<irstPage1e-t <irst
LastPage1e-t Last
PrevPage1e-t Prev
&e-tPage1e-t &e-t
Position 1o%Bottom3Bottom
o Ao$Sorting true
o 'oumns Boo=i" %ro%erties )ea"on+ true
o DataMe+&ames boo=i"
// )n 9ata?eyField $e can specify only single value but in 9ata?ey/ame
$e can specify more than @ using -4.
Pro%erties o# SGDataSource
o D%"ateQuer+
u%"ate tbboo= set boo=1iteZ[boo=1ite, boo=Aut,orZ[boo=Aut,or,
boo=PubZ[boo=Pub, boo=PriceZ[boo=Price $,ere boo=!"Z[boo=!"
- :0 -
// if parameter name is e&ual to columns name then no need of added
parameter to &uery
o DeeteQuer+
Deete #rom tbboo= $,ere boo=!"Z[boo=!"
8ridView1_Sele$ted!ndex4&anged(sender/ e)
{
*ext#ox1.*ext = 8ridView1.Sele$tedCow.4ells91:.*ext;
*ext#ox,.*ext = 8ridView1.Sele$tedCow.4ells9,:.*ext;
*ext#ox+.*ext = 8ridView1.Sele$tedCow.4ells9+:.*ext;
*ext#ox0.*ext = 8ridView1.Sele$tedCow.4ells90:.*ext;
*ext#ox1.*ext = 8ridView1.Sele$tedCow.4ells91:.*ext;
With Co$i&
Page_Load(ob6e$t sender/ E)ent>rgs e)
{
i" (Page.!sPost#a$% == "alse)
{
8rd#ind();
8ridView1_Cow4an$elingEdit(sender/ e)
{
8ridView1.Edit!ndex = L1;
8rd#ind();
8ridView1_CowBpdating(sender/ e)
{
SVl4onne$tion $on = new SVl4onne$tion();
- :1 -
$on.4onne$tionString = 4on"iguration'anager.
4onne$tionStrings9R$sR:.4onne$tionString;
$on.5pen();
SVl4ommand $md = new SVl4ommand();
$md.4ommand*ext =Rupdate tbboo% set boo%*itle=]title/boo%>ut&or=
]aut&or/ boo%Pub=]pub/ boo%Pri$e=]pri$e w&ere boo%!d=]idR;
$md.4onne$tion = $on;
$md.Parameters.>dd(R]idR/SVl2b*7pe.!nt).Value= 4on)ert.*o!nt+,
(((Label)(8ridView1.Cows9e.Cow!ndex:.3ind4ontrol(RlR))).*ext);
$md.Parameters.>dd(R]titleR/ SVl2b*7pe.Var4&ar/ 1P).Value =
((*ext#ox)(8ridView1.Cows9e.Cow!ndex:.3ind4ontrol(Rtb1R))).*ext;
$md.Parameters.>dd(R]aut&orR/ SVl2b*7pe.Var4&ar/ 1P).Value =
((*ext#ox)(8ridView1.Cows9e.Cow!ndex:.3ind4ontrol(Rtb,R))).*ext;
$md.Parameters.>dd(R]pubR/ SVl2b*7pe.Var4&ar/ 1P).Value =
((*ext#ox)(8ridView1.Cows9e.Cow!ndex:.3ind4ontrol(Rtb+R))).*ext;
$md.Parameters.>dd(R]pri$eR/SVl2b*7pe.!nt).Value=4on)ert.*o!nt+,
(((*ext#ox)(8ridView1.Cows9e.Cow!ndex:.3ind4ontrol(Rtb0R))).*ext);
$md.Exe$ute(on\uer7();
$md.2ispose();
8ridView1.Edit!ndex = L1;
8rd#ind();
8ridView1_Cow2eleting(sender/ e)
{
!nt+, eno;
// add 9ata?ey/ame in AridVie$ ;roperty
eno = 4on)ert.*o!nt+,(8ridView1.2ata`e7s
9e.Cow!ndex:9P:);
SVl4onne$tion $on = new SVl4onne$tion();
$on.4onne$tionString = 4on"iguration'anager.
4onne$tionStrings9R$sR:.4onne$tionString;
$on.5pen();
SVl4ommand $md = new SVl4ommand();
$md.4ommand*ext=Rdelete "rom tbboo% w&ere boo%!d=]idR;
$md.4onne$tion = $on;
$md.Parameters.>dd(R]idR/SVl2b*7pe.!nt).Value= eno;
$md.Exe$ute(on\uer7();
$md.2ispose();
8ridView1.Edit!ndex = L1;
8rd#ind();
- :2 -
I 9T6L
;asp@8ridView !2=R8ridView1R runat=Rser)erR<
;4olumns<
;asp@*emplate3ield .eader*ext=Rboo%!dR<
;!tem*emplate<
;GUE)al(Rboo%!dR)G<
;?!tem*emplate<
;Edit!tem*emplate<
;asp@Label !2=RlR
*ext=D;GUE)al(Rboo%!dR)G<Drunat=Rser)erR<
;?asp@Label<
;?Edit!tem*emplate<
;?asp@*emplate3ield<
;asp@*emplate3ield .eader*ext=R(ameR<
;!tem*emplate<
;GUE)al(Rboo%*itleR)G<
;?!tem*emplate<
;Edit!tem*emplate<
;asp@*ext#ox !2=Rtb1R
*ext=D;GUE)al(Rboo%*itleR)G<D runat=Rser)erR<
;?asp@*ext#ox<
;?Edit!tem*emplate<
;?asp@*emplate3ield<
;asp@*emplate3ield .eader*ext=R>ut&orR<
;!tem*emplate<
;GUE)al(Rboo%>ut&orR)G<
;?!tem*emplate<
;Edit!tem*emplate<
;asp@*ext#ox !2=Rtb,R *ext=D;GUE)al(Rboo%>ut&orR)G<D
runat=Rser)erR<
;?asp@*ext#ox<
;?Edit!tem*emplate<
;?asp@*emplate3ield<
;asp@*emplate3ield .eader*ext=RPublis&erR<
;!tem*emplate<
;GUE)al(Rboo%PubR)G<
;?!tem*emplate<
;Edit!tem*emplate<
- :; -
;asp@*ext#ox !2=Rtb+R *ext=D;GUE)al(Rboo%PubR)G<D
runat=Rser)erR<
;?asp@*ext#ox<
;?Edit!tem*emplate<
;?asp@*emplate3ield<
;asp@*emplate3ield .eader*ext=RPri$eR<
;!tem*emplate<
;GUE)al(Rboo%Pri$eR)G<
;?!tem*emplate<
;Edit!tem*emplate<
;asp@*ext#ox !2=Rtb0R *ext=D;GUE)al(Rboo%Pri$eR)G<D
runat=Rser)erR<
;?asp@*ext#ox<
;?Edit!tem*emplate<
;?asp@*emplate3ield<
;asp@*emplate3ield .eader*ext=REditR<
;!tem*emplate<
;asp@Lin%#utton !2=Rlb1R *ext=REditR
4ommand(ame=REditR runat=Rser)erR<
;?asp@Lin%#utton<
;?!tem*emplate<
;Edit!tem*emplate<
;asp@Lin%#utton !2=Rlb+R *ext=RBpdateR
4ommand(ame=RBpdateR runat=Rser)erR<
;?asp@Lin%#utton<
;asp@Lin%#utton !2=Rlb0R *ext=R4an$elR
4ommand(ame=R4an$elR runat=Rser)erR<
;?asp@Lin%#utton<
;?Edit!tem*emplate<
;?asp@*emplate3ield<
;asp@*emplate3ield .eader*ext=R2eleteR<
;!tem*emplate<
;asp@Lin%#utton !2=Rlb,R *ext=R2eleteR
4ommand(ame=R2eleteR runat=Rser)erR<
;?asp@Lin%#utton<
;?!tem*emplate<
;?asp@*emplate3ield<
;?4olumns<
;?asp@8ridView<
- :A -
:. 4RID WIT9IN 4RID
Pace 0ri"vie$.
A"" (eb 'on#ig #ie.
0ri"vie$ %ro%ert+ Auto0enerate'oumn #ase.
0ri"vie$%ro%ert+'oumnsA""21em%ate<ie"6>ea"er1e-t 'ategor+
0ri"vie$%ro%ert+'oumnsA""21em%ate<ie"6>ea"er1e-t Pro"ucts
I 9T6L
;asp@8ridView !2=R8ridView1R runat=Rser)erR
>uto8enerate4olumns=R3alseR .eig&t=R,+YpxR Aidt&=R,WXpxR<
;4olumns<
;asp@*emplate3ield .eader*ext=R4ategor7R<
;!tem*emplate<
;b<!2@;?b<;GUE)al(R$ategor7!dR)G<;br ?<
;b<(ame@;?b<Inbsp; ;GUE)al(R$ategor7(ameR)G<
;?!tem*emplate<
;?asp@*emplate3ield<
;asp@*emplate3ield .eader*ext=RProdu$tsR<
;!tem*emplate<
;asp@8ridView !2=Rg)1R >uto8enerate4olumns=R"alseR
Aidt&=R1PPpxR runat=Rser)erR 2ataSour$e=D;GU8et2ata
(4on)ert.*o!nt+,(E)al(R$ategor7!dR)))G<D<
;4olumns<
;asp@#ound3ield .eader*ext=R!2R
2ata3ield=Rprodu$t!dR ?<
;asp@#ound3ield .eader*ext=R(ameR
2ata3ield=Rprodu$t(ameR ?<
;asp@#ound3ield .eader*ext=RPri$eR
2ata3ield=RunitPri$eR ?<
;?4olumns<
;?asp@8ridView<
;?!tem*emplate<
;?asp@*emplate3ield<
;?4olumns<
- :B -
;?asp@8ridView<
publi$ partial $lass _2e"ault @ S7stem.Aeb.B!.Page
{
prote$ted )oid Page_Load(ob6e$t sender/ E)ent>rgs e)
{
8rd#ind();
pri)ate )oid 8rd#ind()
{
SVl2ata>dapter adp = new SVl2ata>dapter(Rsele$t E "rom
tb$ategor7;sele$t E "rom tbprodu$tR/ 4on"iguration'anager.
4onne$tionStrings9R$sR:.4onne$tionString);
2ataSet ds = new 2ataSet();
adp.3ill(ds);
8ridView1.2ataSour$e = ds;
8ridView1.2ata#ind();
publi$ 2ataSet 8et2ata(!nt+, $id)
{
String st;
st=Rsele$t E "rom tbprodu$t w&ere $atergor7!d=R-$id.*oString();
SVl2ata>dapter adp= new SVl2ata>dapter(st/4on"iguration'anager.
4onne$tionStrings9R$sR:.4onne$tionString);
2ataSet ds = new 2ataSet();
return (ds);
!n t,is Guer+ $i e-ecute man+ time an" t,is $i ea" to %oor %er#ormance
Aother way
publi$ partial $lass _2e"ault @ S7stem.Aeb.B!.Page
{
2ataSet ds = new 2ataSet();
prote$ted )oid Page_Load(ob6e$t sender/ E)ent>rgs e)
{
8rd#ind();
- :: -
pri)ate )oid 8rd#ind()
{
SVl2ata>dapter adp = new SVl2ata>dapter(Rsele$t E "rom
tb$ategor7;sele$t E "rom tbprodu$tR/ 4on"iguration'anager.
4onne$tionStrings9R$sR:.4onne$tionString);
adp.3ill(ds);
8ridView1.2ataSour$e = ds.*ables9P:;
8ridView1.2ata#ind();
publi$ 2ataView 8et2ata(!nt+, $id)
{
2ataView d) = ds.*ables91:.2e"aultView;
// 9ataVie$ is used to store4 filter4 /avigate data. )t is temperory file on client side.
d).Cow3ilter = R$ategor7!d=R - $id.*oString();
return d);
- :@ -
:. 4RAND AND )UBTOTAL
using S7stem.2ata.SVl4lient;
using S7stem.2rawing;
publi$ partial $lass _2e"ault @ S7stem.Aeb.B!.Page
{
prote$ted )oid Page_Load(ob6e$t sender/ E)ent>rgs e)
{
8rd#ind();
pri)ate )oid 8rd#ind()
{
String st;
st = Rsele$t $ase w&en(grouping($ategor7name)=1)
t&en D8.*otalD else $ategor7name end
$ategor7name /$ase w&en
(grouping(produ$tname)=1) t&en DSub *otalD
else produ$tname end produ$tname/
sum(unitpri$e) unitpri$e/sum(unitsinsto$%)
unitsinsto$% "rom produ$ts a/ $ategories b
w&ere a.$ategor7!d=b.$ategor7!d group b7
$ategor7name/ produ$tname wit& rollupR;
SVl2ata>dapter adp=new SVl2ata>dapter(st/4on"iguration'anager.
4onne$tionStrings9R$sR:.4onne$tionString);
2ataSet ds = new 2ataSet();
adp.3ill(ds);
!nt+, i=P;
String p$ = RR;
String n$ = RR;
w&ile (i ; ds.*ables9P:.Cows.4ountL1)
{
n$ = ds.*ables9P:.Cows9i:9P:.*oString();
i" (n$ K= p$)
{
p$ = n$;
2ataCow r;
r = ds.*ables9P:.(ewCow();
- :N -
r91: = p$;
r9,: = L1;
ds.*ables9P:.Cows.!nsert>t(r/ i);
i--;
i--;
2ataCow r1;
r1 = ds.*ables9P:.Cows9i:;
r191: = R8.*otalR;
8ridView1.2ataSour$e = ds;
8ridView1.2ata#ind();
prote$ted )oid 8ridView1_Cow2ata#ound(sender/ e)
{
//8vent in gridvie$ $hich is called for all the ro$s for all templates.
i" (e.Cow.4ells9P:.*ext == RSub *otalR)
{
e.Cow.#a$%4olor = 4olor.8ra7;
i" (e.Cow.4ells9P:.*ext == R8.*otalR)
{
e.Cow.#a$%4olor = 4olor.4&o$olate;
i" (e.Cow.4ells91:.*ext == RL1R)
{
e.Cow.#a$%4olor = 4olor.Pin%;
e.Cow.4ells9P:.4olumnSpan = +;
e.Cow.4ells9P:.3ont.#old = true;
e.Cow.4ells9P:..ori=ontal>lign =
.ori=ontal>lign.4enter;
e.Cow.4ells.Cemo)e>t(,);
e.Cow.4ells.Cemo)e>t(1);
i" (e.Cow.4ells9P:.*ext == R(ameR)
{
e.Cow.#a$%4olor = 4olor.4&o$olate;
- :O -
:U.R; ANAL;5.R
seect isnu 2categor+name,L0.1oataL6,isnu 2%ro"uctname,LSub 1otaL6, sum2unit%rice6
unit%rice,sum2unitsinstoc=6 unitsinstoc= #rom %ro"ucts a, categories b $,ere
a.categor+!"Zb.categor+!" grou% b+ categor+name, %ro"uctname $it, rou%
33 Seect me $o,i coumn name aa+ege 5o grou% b+ me "e#ine ,ote ,ai
33 rou% is a$a+s use $it, 8grou% b+9
33 1,is Guer+ $i re%ace a nu $it, 8Sub 1ota9 it not c,ec= $,ere it is en" o# categor+
or nu in %ro"uct name coumn t,at + $e use secon" Guer+.
TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT
seect case $,en2grou%ing2categor+name6Z16 t,en L0.1otaL ese categor+name en"
categor+name,case $,en2grou%ing2%ro"uctname6Z16 t,en LSub 1otaL ese %ro"uctname
en" %ro"uctname, sum2unit%rice6 unit%rice,sum2unitsinstoc=6 unitsinstoc= #rom %ro"ucts,
sum2unit%rice6 unit%rice,sum2unitsinstoc=6 unitsinstoc= #rom %ro"ucts a, categories b
$,ere a.categor+!"Zb.categor+!" grou% b+ categor+name, %ro"uctname $it, rou%
a, categories b $,ere a.categor+!"Zb.categor+!" grou% b+ categor+name, %ro"uctname
$it, rou%
- @0 -
:. ADD IT.6) IN TABL.
Pace 0ri"vie$
A"" (eb con#ig #ie n ma=e connection string
0ri"vie$ %ro%erties auto0enrate'oumns #ase
'ic= on t,e tas=s menu o# gri"vie$ 7"it 1em%ate
'ic= on 7m%no in "is%a+ an" in its 1em%ate a"" $,at so ever contro u $ant
t,en cic= on a""e" "ata bin"ings an" $rite co"e in co"e e-%ression 2i=e
7va28em%no966
Do same #or ot,er cooums.
(,en $e mention comman" name o# our c,oice t,en t,at is come un"er
)o$'omman" event
using S7stem.2ata.SVl4lient;
publi$ partial $lass _2e"ault @ S7stem.Aeb.B!.Page
{
SVl4onne$tion $on = new SVl4onne$tion();
prote$ted )oid Page_Load(ob6e$t sender/ E)ent>rgs e)
{
i" (KPage.!sPost#a$%)
{
8rd#ind();
pri)ate )oid 8rd#ind()
{
SVl2ata>dapter adp = new SVl2ata>dapter(Rsele$t E "rom tbempR/
4on"iguration'anager.4onne$tionStrings9R$sR:.4onne$tionString);
2ataSet ds = new 2ataSet();
adp.3ill(ds);
8ridView1.2ataSour$e = ds;
8ridView1.2ata#ind();
prote$ted )oid 8ridView1_Cow4ommand(sender/ e)
{
- @1 -
i" (e.4ommand(ame == Sa)e)
{
!nt+, eno/ es;
String en/ eadd;
eno= 4on)ert.*o!nt+,(((Label)
(8ridView1.3ooterCow.3ind4ontrol(Rlabel+R))).*ext);
es= 4on)ert.*o!nt+,(((*ext#ox)
(8ridView1.3ooterCow.3ind4ontrol(RtextboxWR))).*ext);
en = ((*ext#ox)
(8ridView1.3ooterCow.3ind4ontrol(Rtextbox,R))).*ext;
eadd = ((*ext#ox)
(8ridView1.3ooterCow.3ind4ontrol(Rtextbox0R))).*ext;
i" ($on.State == 4onne$tionState.4losed)
{
$on.4onne$tionString = 4on"iguration'anager.
4onne$tionStrings9R$sR:.4onne$tionString;
$on.5pen();
SVl4ommand $md = new SVl4ommand();
$md.4ommand*ext = Rinsert into tbemp
)alues(]eno/]en/]eadd/]es)R;
$md.4onne$tion = $on;
$md.Parameters.>dd(R]enoR/ SVl2b*7pe.!nt).Value=eno;
$md.Parameters.>dd(R]enR/ SVl2b*7pe.Var4&ar/1P).Value=en;
$md.Parameters.>dd(R]eaddR/ SVl2b*7pe.Var4&ar/ 1P).Value=eadd;
$md.Parameters.>dd(R]esR/ SVl2b*7pe.!nt).Value = es;
$md.Exe$ute(on\uer7();
// $e can also use adp.insert!ommand B cmd
$md.2ispose();
8rd#ind();
publi$ !nt+, >uto8en()
{
SVl4ommand $md = new SVl4ommand();
i" ($on.State==4onne$tionState.4losed)
{
$on.4onne$tionString = 4on"iguration'anager.
4onne$tionStrings9R$sR:.4onne$tionString;
$on.5pen();
$md.4ommand*ext = Rsele$t is(ull(max(empno)/ P) "rom tbempR;
$md.4onne$tion = $on;
!nt+, r = 4on)ert.*o!nt+,($md.Exe$uteS$alar())- 1;
- @2 -
$md.2ispose();
return r;
prote$ted )oid 8ridView1_CowEditing(sender/e)
{
8ridView1.Edit!ndex = e.(ewEdit!ndex;
8rd#ind();
prote$ted )oid 8ridView1_Cow2eleting(sender/ e)
{
!nt+, eno;
// add 9ata?ey/ame in AridVie$ ;roperty
eno = 4on)ert.*o!nt+,(8ridView1.2ata`e7s
9e.Cow!ndex:9P:);
i" ($on.State == 4onne$tionState.4losed)
{
$on.4onne$tionString = 4on"iguration'anager.
4onne$tionStrings9R$sR:.4onne$tionString;
$on.5pen();
SVl4ommand $md = new SVl4ommand();
$md.4ommand*ext = Rdelete "rom tbemp w&ere empno=]enoR;
$md.4onne$tion = $on;
$md.Parameters.>dd(R]enoR/ SVl2b*7pe.!nt).Value=eno;
$md.Exe$ute(on\uer7();
$md.2ispose();
8rd#ind();
prote$ted )oid 8ridView1_CowBpdating(sender/ e)
{
!nt+, eno/ es;
String en/ eadd;
eno = 4on)ert.*o!nt+,(((Label)(8ridView1.Cows9e.Cow!ndex:.
3ind4ontrol(Rlabel,R))).*ext);
es = 4on)ert.*o!nt+,(((*ext#ox) (8ridView1.Cows9e.Cow!ndex:.
3ind4ontrol(Rtextbox1R))).*ext);
en = ((*ext#ox)(8ridView1.Cows
9e.Cow!ndex:.3ind4ontrol(Rtextbox1R))).*ext;
eadd = ((*ext#ox)(8ridView1.Cows9e.Cow!ndex:.
3ind4ontrol(Rtextbox+R))).*ext;
i" ($on.State == 4onne$tionState.4losed)
{
$on.4onne$tionString = 4on"iguration'anager.
- @; -
4onne$tionStrings9R$sR:.4onne$tionString;
$on.5pen();
SVl4ommand $md = new SVl4ommand();
$md.4ommand*ext = Rupdate tbemp set ename=]en/ eaddress=]eadd/
esal=]es w&ere empno=]enoR;
$md.4onne$tion = $on;
$md.Parameters.>dd(R]enoR/ SVl2b*7pe.!nt).Value = eno;
$md.Parameters.>dd(R]enR/ SVl2b*7pe.Var4&ar/ 1P).Value = en;
$md.Parameters.>dd(R]eaddR/ SVl2b*7pe.Var4&ar/1P).Value=eadd;
$md.Parameters.>dd(R]esR/ SVl2b*7pe.!nt).Value = es;
$md.Exe$ute(on\uer7();
$md.2ispose();
8ridView1.Edit!ndex = L1;
8rd#ind();
prote$ted )oid 8ridView1_Cow4an$elingEdit(sender/ e)
{
8ridView1.Edit!ndex = L1;
8rd#ind();
- @A -
:. TO DI)*LA; DATA IN T.<TBO< 'U)T CLIC2IN4 ON ROW
Pace 0ri"vie$ c,ose "ata source
Pace SQLDataSource an" con#igure it.
0ri"Vie$ 2%ro%erties6'oumns'omman"<ie"a"" Seect%ro%erties
Visibe Z
#ase
prote$ted )oid 8ridView1_Cow2ata#ound(sender/ e)
{
i" (e.Cow.Cow*7pe == 2ata4ontrolCow*7pe..eader)
{
else i" (e.Cow.Cow*7pe == 2ata4ontrolCow*7pe.3ooter)
{
else
{
Lin%#utton l% = (Lin%#utton)(e.Cow.4ells9W:.4ontrols9P:);
e.Cow.>ttributes9Ron4li$%R: = 4lientS$ript.
8etPost#a$%4lient.7perlin%(l%/ RR);
I 9T6L
- @B -
;G] Page Language=R4UR EnableEventValidation="false"...G<
:. TO ).L.CT COLU6N) TO B. DI)*LA; AT RUN TI6.
Pace 0ri"vie$
A"" $eb con#ig #ie
Pace ',ec=Bo- ist
Pace button
using S7stem.2ata.SVl4lient;
publi$ partial $lass _2e"ault @ S7stem.Aeb.B!.Page
{
prote$ted )oid Page_Load(ob6e$t sender/ E)ent>rgs e)
{
i"(KPage.!sPost#a$%)
{
SVl4onne$tion $on = new SVl4onne$tion();
$on.4onne$tionString = 4on"iguration'anager.
4onne$tionStrings9R$sR:.4onne$tionString;
$on.5pen();
SVl4ommand $md = new SVl4ommand();
$md.4ommand*ext = Rsele$t E "rom tbboo%R;
$md.4onne$tion = $on;
SVl2ataCeader dr = $md.Exe$uteCeader();
!nt+, i;
"or (i = P; i ; dr.3ield4ount; i--)
{
4&e$%#oxList1.!tems.>dd(dr.8et(ame(i).*oString());
33 to get t,e vaue o# t,at coumn $e can use 0etVaue
prote$ted )oid #utton1_4li$%(sender/ E)ent>rgs e)
{
String st = RR;
!nt+, i;
"or (i = P; i ; 4&e$%#oxList1.!tems.4ount; i--)
- @: -
{
i" (4&e$%#oxList1.!tems9i:.Sele$ted == true)
{
st -= 4&e$%#oxList1.!tems9i:.*ext - R/R;
st = st.Substring(P/ st.Lengt& L 1);
String st1 = Rsele$t R - st - R "rom tbboo%R;
SVl2ata>dapter adp=new SVl2ata>dapter(st1/4on"iguration
'anager.4onne$tionStrings9R$sR:.4onne$tionString);
2ataSet ds = new 2ataSet();
adp.3ill(ds);
8ridView1.2ataSour$e = ds;
8ridView1.2ata#ind();
- @@ -
D.TAILVI.W
Simiar to 0ri"Vie$
$e can "is%a+ on+ singe recor"
!n buit %aging
Auto e"iting, "eete, insert
(e "is%a+ #ie"s in ro$s but in gri"vie$ $e "is%a+ #ie"s in coumns
!n t,is t,ere is Auto0enrate)o$
'omman" name
o 7"it
o D%"ate
o 'ance
o Deete
o &e$
o !nsert
(e use Detai vie$ #or singe recor" o%eration .
Pace DetaiVie$, SGDataSource an" con#igure t,em
Pro%erties o# DetaiVie$
o Auto0enerateDeeteButton true
o Auto0enerate7"itButton true
o Auto0enerate!nsertButton true
o Ao$Paging true
o DataMe+&ames boo=i"
Pro%erties o# SGDataSource
o D%"ateQuer+
u%"ate tbboo= set boo=1iteZ[boo=1ite, boo=Aut,orZ[boo=Aut,or,
boo=PubZ[boo=Pub, boo=PriceZ[boo=Price $,ere boo=!"Z[boo=!"
o DeeteQuer+
Deete #rom tbboo= $,ere boo=!"Z[boo=!"
o !nsertQuer+
!nsert into tbem% vaues2[em%no,[ename,[ea""ress,[esa6
- @N -
!# %arameter name are "i##erent #rom coumns name
2etailsView1_!temBpdating(sender/ e)
{
SVl2ataSour$e1.BpdateParameters9RenoR:.2e"aultValue =
e.`e7s9P:.*oString();
//"nother $ay
??SVl2ataSour$e1.BpdateParameters9RenoR:.2e"aultValue=((*ext#ox)
(2etailsView1.Cows9P:.4ells91:.4ontrols9P:)).*ext;
SVl2ataSour$e1.BpdateParameters9RenR:.2e"aultValue =
e.(ewValues91:.*oString();
/* $henever $e use update then t$o arrays are ma(e one contaning old values other $ith
ne$ values. )n $e refer to array $ith values as /e$ValuesC D*/
SVl2ataSour$e1.BpdateParameters9RedR:.2e"aultValue =
e.(ewValues9,:.*oString();
SVl2ataSour$e1.BpdateParameters9ResR:.2e"aultValue =
e.(ewValues9+:.*oString();
2etailsView1_!tem!nserting(sender/ e)
{
SVl2ataSour$e1.!nsertParameters9RenoR:.2e"aultValue=((*ext#ox)
(2etailsView1.Cows9P:.4ells91:.4ontrols9P:)).*ext;
SVl2ataSour$e1.!nsertParameters9RenR:.2e"aultValue=((*ext#ox)
(2etailsView1.Cows91:.4ells91:.4ontrols9P:)).*ext;
SVl2ataSour$e1.!nsertParameters9RedR:.2e"aultValue=((*ext#ox)
(2etailsView1.Cows9,:.4ells91:.4ontrols9P:)).*ext;
SVl2ataSour$e1.!nsertParameters9ResR:.2e"aultValue=((*ext#ox)
(2etailsView1.Cows9+:.4ells91:.4ontrols9P:)).*ext;
2etailsView1_!tem2eleting(sender/ e)
{
SVl2ataSour$e1.BpdateParameters9RenoR:.2e"aultValue=
e.`e7s9P:.*oString();
- @O -
D.TAIL V.IW WIT9 CODIN4
Pace DetaiVei$
A"" (eb 'on#ig <ie
DetaiVei$ %ro%erties Auto0enrate)o$s #ase
DetaiVei$ %ro%erties #ie"s A"" tem%ate #ie"s
o 7m%no
o &ame
o A""ress
o Saar+
o <or buttons
DetaiVei$ 1as=s 7"it 1em%ates
o 7m%no
!tem1em%Labe7"itDataBin"ing co"e7va28em%no96
7"it!tem1emLabe7"itDataBin"ing co"e7va28em%no96
!nsert!tem1e-tbo-7"itDataBin"ing co"e7va28em%no96
o 7name
!tem1em%Labe7"itDataBin"ing co"e7va28ename96
7"it!tem1em1e-tbo-7"itDataBin"inco"e7va28ename96
!nsert!tem1e-tbo-7"itDataBin"ing co"e7va28ename96
o 7a""ress
!tem1em%Labe7"itDataBin"ing co"e7va28ea""96
7"it!tem1em1e-tBo-7"itDataBin"ing co"e7va28ea""96
!nsert!tem1e-tbo-7"itDataBin"ing co"e7va28ea""96
o 7sa
!tem1em%Labe7"itDataBin"ing co"e7va28esa96
7"it!tem1em1e-tbo-7"itDataBin"ing co"e7va28esa96
!nsert!tem1e-tbo-7"itDataBin"ing co"e7va28esa96
o Buttons
!tem1em% Lin=Buttons
7"it 2'omman"&ame e"it6
- N0 -
&e$ 2'omman"&ame ne$6
Deete2'omman"&ame "eete6
7"it!tem1em1e-tbo-7"itDataBin"ing co"e7va28esa96
D%"ate 2'omman"&ame u%"ate6
'ance 2'omman"&ame 'ance6
!nsert!tem1e-tbo-7"itDataBin"ing co"e7va28esa96
Save 2'omman"&ame !nsert6
'ance 2'omman"&ame 'ance6
o 7m%t+ Data 1em%ate //5o sho$ table if no data available
!tem1em% Lin=Buttons
A"" Data to 1abe 2'omman"&ame ne$6
using S7stem.2ata.SVl4lient;
publi$ partial $lass _2e"ault @ S7stem.Aeb.B!.Page
{
prote$ted )oid Page_Load(ob6e$t sender/ E)ent>rgs e)
{
i" (KPage.!sPost#a$%)
{
2etail#ind();
pri)ate )oid 2etail#ind()
{
SVl2ata>dapter adp = new SVl2ata>dapter(Rsele$t E "rom tbempR/
4on"iguration'anager.4onne$tionStrings9R$sR:.4onne$tionString);
2ataSet ds = new 2ataSet();
adp.3ill(ds);
2etailsView1.2ataSour$e = ds;
2etailsView1.2ata#ind();
prote$ted )oid 2etailsView1_'ode4&anging(sender/ e)
{
i" (e.(ew'ode == 2etailsView'ode.Edit)
{
2etailsView1.4&ange'ode(2etailsView'ode.Edit);
// for 8dit)tem5emplate
else i" (e.(ew'ode == 2etailsView'ode.!nsert)
{
2etailsView1.4&ange'ode(2etailsView'ode.!nsert);
// for )nsert)tem5emplate
- N1 -
else
{
2etailsView1.4&ange'ode(2etailsView'ode.Cead5nl7);
// for )tem5emplate
2etail#ind();
prote$ted )oid 2etailsView1_!tem2eleting(sender/ e)
{
!nt+, eno;
eno = 4on)ert.*o!nt+,(((Label)(2etailsView1.
Cows9P:.3ind4ontrol(Rlabel1R))).*ext);
SVl4onne$tion $on = new SVl4onne$tion();
$on.4onne$tionString = 4on"iguration'anager.
4onne$tionStrings9R$sR:.4onne$tionString;
$on.5pen();
SVl4ommand $md = new SVl4ommand();
$md.4ommand*ext = Rdelete "rom tbemp w&ere empno=]enoR;
$md.4onne$tion = $on;
$md.Parameters.>dd(R]enoR/ SVl2b*7pe.!nt).Value = eno;
$md.Exe$ute(on\uer7();
$md.2ispose();
2etail#ind();
I 9T6L
;st7le t7pe=Rtext?$ssR<
.ab${"ontLsi=e@larger;"ontLweig&t@bold
.x7={2ispla7@none;)isibilit7@&idden
;?st7le<
;s$ript t7pe=Rtext?6a)as$riptR<
"un$tion 8et2ata(id)
{
)ar e;
$olor(id);
e=do$ument.getElement#7!d(DdD-id);
i"(e)
{
i"(e.st7le.displa7K=Dblo$%D)
{
e.st7le.displa7=Dblo$%D;
e.st7le.)isibilit7=D)isibleD;
else
{
e.st7le.displa7=DnoneD;
e.st7le.)isibilit7=D&iddenD;
- NN -
"or()ar i=P;i;1,;i--)
{
i"(i==id)
{
i--;
)ar e1=do$ument.getElement#7!d(DdD-i);
i"(e1)
{
e1.st7le.displa7=DnoneD;
e1.st7le.)isibilit7=D&iddenD;
"un$tion $olor(id)
{
)ar e1;
e1=do$ument.getElement#7!d(D&D-id);
i"(e1)
{
e1.st7le.$olor=DblueD;
"or()ar i=P;i;1,;i--)
{
i"(i==id)
{
i--;
e,=do$ument.getElement#7!d(D&D-i);
i"(e,)
{
e,.st7le.$olor=Dbla$%D;
;?s$ript<
;?&ead<
;bod7<
;"orm id=R"orm1R runat=Rser)erR<
;di) st7le=RtextLalign@ 6usti"7R<
Sele$t *&e 4ategor7@
;asp@2rop2ownList !2=R2rop2ownList1R runat=Rser)erR
>utoPost#a$%=R*rueR 5nSele$ted!ndex4&anged=
- NO -
R2rop2ownList1_Sele$ted!ndex4&angedR <
;?asp@2rop2ownList<;br ?<
;asp@8ridView !2=R8ridView1R runat=Rser)erR Aidt&=RWX+pxR
>uto8enerate4olumns=R3alseR<
;4olumns<
;asp@*emplate3ield<
;!tem*emplate<
;asp@4&e$%#ox !2=R$bR runat=Rser)erR ?<
;?!tem*emplate<
;?asp@*emplate3ield<
;asp@*emplate3ield .eader*ext=RProdu$t!dR<
;!tem*emplate<
;GUE)al(RProdu$t!dR)G<
;?!tem*emplate<
;?asp@*emplate3ield<
;asp@*emplate3ield .eader*ext=R(ameR<
;!tem*emplate<
;di) id=D&;GU2ata#inder.E)al(4ontainer/RCow!ndexR)G<D
$lass=Dab$D ondbl$li$%=D8et2ata (;GU2ata#inder.
E)al(4ontainer/RCow!ndexR)G<);D on$li$%=D$olor
(;GU2ata#inder.E)al(4ontainer/RCow!ndexR)G<);D<
;asp@Label !2=Rl1R
*ext=D;GUE)al(RProdu$t(ameR)G<D
runat=Rser)erR<
;?asp@Label<
;?di)<
;di) id=Dd;GU2ata#inder.E)al(4ontainer/RCow!ndexR)G<D
$lass=Dx7=D ondbl$li$%=D8et2ata(;GU2ata#inder.
E)al(4ontainer/RCow!ndexR)G<);D on$li$%=D$olor
(;GU2ata#inder.E)al(4ontainer/RCow!ndexR)G<);D<
;b<Supplier (ame@;?b<;GUE)al(R4ompan7(ameR)G<;br ?<
;b<Supplier >ddress@;?b<;GUE)al(R>ddressR)G<;br ?<
;b<4it7@;?b<Inbsp;Inbsp;Inbsp;;GUE)al(R$it7R)G<;br ?<
;b<P&one@;?b<Inbsp;Inbsp;Inbsp;;GUE)al(Rp&oneR)G<;br ?<
;b<\uantit7 per unit@;?b<;GUE)al(R\uantit7PerBnitR)G<;br ?<
;b<Bnits on 5rder@;?b<;GUE)al(RBnits5n5rderR)G<;br ?<
;?di)<
;?!tem*emplate<
;?asp@*emplate3ield<
;asp@*emplate3ield .eader*ext=RBnit Pri$eR<
;!tem*emplate<
- O0 -
;asp@Label !2=Rl,R *ext=D;GUE)al(RBnitPri$eR)G<D
runat=Rser)erR<;?asp@Label<
;?!tem*emplate<
;?asp@*emplate3ield<
;asp@*emplate3ield .eader*ext=RSto$%R<
;!tem*emplate<
;GUE)al(RBnits!nSto$%R)G<
;?!tem*emplate<
;?asp@*emplate3ield<
;?4olumns<
;?asp@8ridView<
;asp@8ridView !2=R8ridView,R runat=Rser)erR
>uto8enerate4olumns=R3alseR<
;4olumns<
;asp@#ound3ield .eader*ext=RProdu$t (ameR
2ata3ield=RProdu$t(ameR ?<
;asp@#ound3ield .eader*ext=RPri$eR 2ata3ield=RPri$eR ?<
;asp@*emplate3ield<
;3ooter*emplate<
;asp@Lin%#utton !2=RLin%#utton1R runat=Rser)erR
4ommand(ame=R#u7R<#u7
;?asp@Lin%#utton<
;?3ooter*emplate<
;?asp@*emplate3ield<
;?4olumns<
;?asp@8ridView<
;?di)<
;?"orm<
;?bod7<
;?.*'L<
- O1 -
FOR6VI.W
Simiar to DetaiVie$
$e can "is%a+ on+ singe recor"
!n buit %aging
(e "is%a+ #ie"s in ro$s
!n t,is t,ere is no Auto0enrate )o$ or coumns
&o Limitation, &o De#aut 1em%ate
'omman" name
o 7"it
o D%"ate
o 'ance
o Deete
o &e$
o !nsert
(e use #rom vie$ #or singe recor" o%eration .
&o <ie" an" coumns Avaiabe
<u+ customi?e vie$
!t is 5ust i=e #orm
Pace <ormVei$, A"" (eb 'on#ig <ie
DetaiVei$ 1as=s 7"it 1em%ates !tem1em%ate
o (rite 7m%no, %ace Labe7"itDataBin"ing co"e7va28em%no96
o (rite 7name, %ace Labe7"itDataBin"ing co"e7va28ename96
o (rite 7a""ress, %ace Labe7"itDataBin"inco"e7va28ename96
o (rite 7sa, %ace Labe7"itDataBin"ing co"e7va28esa96
- O2 -
o Pace Lin=Buttons
7"it 2'omman"&ame e"it6
&e$ 2'omman"&ame ne$6
Deete2'omman"&ame "eete6
7"it!tem1em%ate
o (rite 7m%no, %ace Labe7"itDataBin"ing co"e7va28em%no96
o (rite 7name, %ace 1e-tbo-7"itDataBin"ing co"e7va28ename96
o (rite 7a""ress, %ace 1e-tbo-7"itDataBin"inco"e7va28ename96
o (rite 7sa, %ace 1e-tbo-7"itDataBin"ing co"e7va28esa96
o Pace Lin=Buttons
D%"ate 2'omman"&ame u%"ate6
'ance 2'omman"&ame 'ance6
!nsert!tem1em%ate
o (rite 7m%no, %ace 1e-tbo-7"itDataBin"ing co"e7va28em%no96
o (rite 7name, %ace 1e-tbo-7"itDataBin"ing co"e7va28ename96
o (rite 7a""ress, %ace 1e-tbo-7"itDataBin"inco"e7va28ename96
o (rite 7sa, %ace 1e-tbo-7"itDataBin"ing co"e7va28esa96
o Pace Lin=Buttons
Save 2'omman"&ame !nsert6
'ance 2'omman"&ame 'ance6
7m%t+Data1em%ate //5o sho$ table if no data available
o (rite &o Data Avaiabe
o A"" Lin=Buttons
A"" Data to 1abe 2'omman"&ame ne$6
using S7stem.2ata.SVl4lient;
publi$ partial $lass _2e"ault @ S7stem.Aeb.B!.Page
{
prote$ted )oid Page_Load(ob6e$t sender/ E)ent>rgs e)
{
i" (KPage.!sPost#a$%)
{
3rm#ind();
pri)ate )oid 3rm#ind()
{
SVl2ata>dapter adp = new SVl2ata>dapter(Rsele$t E "rom tbempR/
4on"iguration'anager.4onne$tionStrings9R$sR:.4onne$tionString);
2ataSet ds = new 2ataSet();
adp.3ill(ds);
3ormVeiw1.2ataSour$e = ds;
3ormView1.2ata#ind();
- O; -
prote$ted )oid 3ormView1_'ode4&anging(sender/ e)
{
i" (e.(ew'ode == 3ormView'ode.Edit)
{
3ormView1.4&ange'ode(3ormView'ode.Edit);
// for 8dit)tem5emplate
else i" (e.(ew'ode == 3ormView'ode.!nsert)
{
3ormView1.4&ange'ode(3ormView'ode.!nsert);
// for )nsert)tem5emplate
else
{
3ormView1.4&ange'ode(3ormView'ode.Cead5nl7);
// for )tem5emplate
3orm#ind();
prote$ted )oid 3ormView1_!tem2eleting(sender/ e)
{
!nt+, eno;
eno = 4on)ert.*o!nt+,(((Label)(3ormView1.
3ind4ontrol(Rlabel1R))).*ext);
SVl4onne$tion $on = new SVl4onne$tion();
$on.4onne$tionString = 4on"iguration'anager.
4onne$tionStrings9R$sR:.4onne$tionString;
$on.5pen();
SVl4ommand $md = new SVl4ommand();
$md.4ommand*ext = Rdelete "rom tbemp w&ere empno=]enoR;
$md.4onne$tion = $on;
$md.Parameters.>dd(R]enoR/ SVl2b*7pe.!nt).Value = eno;
$md.Exe$ute(on\uer7();
$md.2ispose();
3orm#ind();
CLA)).)
'oection o# simiar t+%e o# "ata
*b5ects can use eac, n ever+ members
1+%es.
&on com%ie" casses
o 'om%ie $it, %ro5ect
o Sco%e $it,in t,e %ro5ect
(ebsite A"" ne$ items cass
!mports S7stem.2ata
!mports S7stem.2ata.SVl4lient
!mports S7stem.4on"iguration
(amespa$e nsEmp
Publi$ 4lass $ls$om"untion
Publi$ S&ared Sub 3ill_2ata(#7Val Vr7 >s String/
#7Val ob6 >s List4ontrol/
#7Val datatext >s String/
#7Val data)alue >s String)
2im adp >s (ew SVl2ata>dapter(Vr7/
R2ata#ase=dbemp;uid=saR)
2im ds >s (ew 2ataSet
- O: -
adp.3ill(ds)
ob6.2ata*ext3ield = datatext
ob6.2ataValue3ield = data)alue
ob6.2ataSour$e = ds
ob6.2ata#ind()
End Sub
End 4lass
Publi$ 4lass $lsEmp
Publi$ eno >s !nt+,
Publi$ en >s String
Publi$ eadd >s String
Publi$ es >s !nt+,
E $e don3t use public variable $e use public properties co% they can be readonly4
E $riteonly4 validation 2 chec(s4 for security
Publi$ Sub (ew() E !onstructor
eno = 11
en = RSa$&inR
eadd = R>mbalaR
es = ,+PPP
End Sub
Publi$ 3un$tion disp() >s String
Ceturn REmpno@ R I eno I RE(ame@ R I en I R
>ddress@ R I eadd I REsal@ R I es
End 3un$tion
End 4lass
Publi$ 4lass $lsEmp1
Pri)ate eno >s !nt+,
Pri)ate en >s String
Pri)ate eadd >s String
Pri)ate es >s String
Publi$ Sub (ew()
eno = 11
en = R8uptaR
eadd = R4anttR
es = R,PPPPR
End Sub
Publi$ Propert7 p_empno() >s !nt+,
8et
Ceturn eno
End 8et
Set(#7Val )alue >s !nt+,)
eno = )alue
- O@ -
End Set
End Propert7
Publi$ Propert7 p_ename() >s String
8et
Ceturn en
End 8et
Set(#7Val )alue >s String)
en = )alue
End Set
End Propert7
Publi$ Propert7 p_eadd() >s String
8et
Ceturn eadd
End 8et
Set(#7Val )alue >s String)
eadd = )alue
End Set
End Propert7
Publi$ Propert7 p_esal() >s !nt+,
8et
Ceturn es
End 8et
Set(#7Val )alue >s !nt+,)
es = )alue
End Set
End Propert7
Publi$ 3un$tion disp() >s String
Ceturn REmpno@ R I p_empno I RE(ame@ R I
p_ename I R >ddress@ R I p_eadd I REsal@ R
I p_esal
End 3un$tion
End 4lass
Publi$ 4lass $lsEmp,
S&ared $tr >s !nt+, E Shared B Static
Publi$ Sub (ew()
$tr -= 1
End Sub
Publi$ Cead5nl7 Propert7 p_$tr() >s !nt+,
8et
Ceturn $tr
End 8et
- ON -
End Propert7
End 4lass
End (amespa$e
Pace te-tbo-
Pace t,ree buttons
Pace Dro%Do$nList
Partial 4lass _2e"ault
!n&erits S7stem.Aeb.B!.Page
#utton1_4li$%() .andles #utton1.4li$%
2im ob6 >s (ew nsEmp.$lsEmp
ob6.eno = WW
ob6.en = R sa$&in guptaR
ob6.eadd = RCamnagarR
ob6.es = ,+PPQ
*ext#ox1.*ext = ob6.disp()
End Sub
#utton,_4li$%() .andles #utton,.4li$%
2im ob6 >s (ew nsEmp.$lsEmp1
ob6.p_empno = WW
ob6.p_ename = R sa$&in guptaR
ob6.p_eadd = R1WL1Q CamnagarR
ob6.p_esal = ,+PPQ
*ext#ox1.*ext = ob6.disp()
End Sub
#utton+_4li$%() .andles #utton+.4li$%
2im ob6 >s (ew nsEmp.$lsEmp,
*ext#ox1.*ext = ob6.p_$tr
Fob#.pGctr B @@@ error
End Sub
Page_Load() .andles 'e.Load
nsEmp.$ls$om"untion.3ill_2ata(RSele$t E "rom
bempR/ 2rop2ownList1/ RenameR/ RempnoR)
End Sub
End 4lass
- OO -
OV.RLOADIN4 AND OV.RRIDIN4
(amespa$e nsemp
Publi$ 'ust!n&erit 4lass $lsemp
FMust)nherit is same as abstact
Prote$ted esal >s !nt+,
Publi$ Sub (ew()
esal = ,PPPP
End Sub
Foverriding al$ays use $ith inheritance
Fsame signature of override method
Fthere is single copy of method
Publi$ 5)erridable 3un$tion 4al>lw() >s !nt+,
Ceturn esal E 1P ? 1PP
End 3un$tion
Publi$ 'ust5)erride Propert7 p_sal() >s !nt+,
FMustHver:ide only declare in abstact class and the class $hich inherit this must
E override this method
Publi$ 3un$tion S&adow(#7Val p" >s !nt+,) >s !nt+,
Ceturn esal E p" ? 1PP
End 3un$tion
End 4lass
- 100 -
Publi$ 4lass $lsgenemp
!n&erits $lsemp
Publi$ 5)errides Propert7 p_sal() >s !nteger
8et
Ceturn '7#ase.esal
End 8et
Set(#7Val )alue >s !nteger)
'7#ase.esal = )alue
End Set
End Propert7
End 4lass
Publi$ 4lass $ls)ipemp
!n&erits $lsemp
Publi$ 5)errides 3un$tion 4al>lw() >s !nteger
Ceturn '7#ase.esal E ,P ? 1PP
End 3un$tion
F myBase refer to base class and in c, $e use Base (ey$ord
Publi$ 5)errides Propert7 p_sal() >s !nteger
8et
Ceturn '7#ase.esal
End 8et
Set(#7Val )alue >s !nteger)
'7#ase.esal = )alue
End Set
End Propert7
Publi$ S&adows 3un$tion s&adow(#7Val p" >s !nt+,/
#7Val tax >s !nt+,) >s !nt+,
Ceturn '7#ase.esal E p" ? 1PP - '7#ase.esal E
tax ? 1PP
End 3un$tion
Publi$ S&adows 3un$tion s&adow(#7Val p" >s !nt+,/
#7Val tax >s !nt+,/ #7Val loan >s !nt+,) >s !nt+,
Ceturn '7#ase.esal E p" ? 1PP - '7#ase.esal E
tax ? 1PP - '7#ase.esal E loan ? 1PP
End 3un$tion
End 4lass
Publi$ 4lass $ls$ust
- 101 -
!n&erits $lsemp
Publi$ S&adows s&adow >s !nt+,
Publi$ 5)errides Propert7 p_sal() >s !nteger
8et
End 8et
Set(#7Val )alue >s !nteger)
End Set
End Propert7
End 4lass
Publi$ 4lass 4onstru$tor5)erloading
Publi$ Sub (ew()
End Sub
Publi$ Sub (ew(#7Val a >s String)
End Sub
Publi$ Sub (ew(#7Val a >s String/ #7Val b >s !nt+,)
End Sub
Publi$ Sub (ew(#7Val a >s !nt+,)
End Sub
End 4lass
End (amespa$e
DATABA). 9ANDLIN4 WIT9 CLA)) =VB.Net>
A"" (ebcon#ig #ie
A"" a cass #ie
Pace A te-tbo-s
Pace A button an" a istbo- AutoPostBac= true
!mports S7stem.2ata.SVl4lient
!mports S7stem.2ata
!mports S7stem.4on"iguration
(amespa$e nsemp
Publi$ !nter"a$e int$om
Sub Sa)e_Ce$()
Sub Bpdate_Ce$()
Sub 2elete_Ce$()
3un$tion 3ind_re$() >s 2ataSet
End !nter"a$e
Publi$ !nter"a$e intemp
Propert7 p_empno() >s !nt+,
Propert7 p_ename() >s String
Propert7 p_eadd() >s String
- 102 -
Propert7 p_esal() >s String
End !nter"a$e
Publi$ 'ust!n&erit 4lass $ls$on
Prote$ted $on >s (ew SVl4onne$tion
Publi$ Sub (ew()
$on.4onne$tionString = 4on"iguration'anager.
4onne$tionStrings(R$sR).4onne$tionString
End Sub
End 4lass
Publi$ 4lass $lsemp
!n&erits $ls$on
!mplements int$om/ intemp
Fphele class inherit then implement interface
Pri)ate eno >s !nt+,
Pri)ate en >s String
Pri)ate ed >s String
Pri)ate es >s !nt+,
Publi$ Sub 2elete_Ce$()
!" $on.State = 4onne$tionState.4losed *&en
$on.5pen()
End !"
2im $md >s (ew SVl4ommand(RdelempR/ $on)
$md.4ommand*7pe = 4ommand*7pe.StoredPro$edure
$md.Parameters.>dd(R]enoR/SVl2b*7pe.!nt).Value
= p_empno
$md.Exe$ute(on\uer7()
$md.2ispose()
$on.4lose()
End Sub
Publi$ 3un$tion 3ind_re$() >s S7stem.2ata.2ataSet
Eit $ill open connection and after use close it
2im adp >s (ew SVl2ata>dapter(R"indempR/ $on)
adp.Sele$t4ommand.Parameters.>dd(R]enoR/
SVl2b*7pe.!nt).Value = p_empno
adp.Sele$t4ommand.4ommand*7pe = 4ommand*7pe.
StoredPro$edure
2im ds >s (ew 2ataSet()
adp.3ill(ds)
- 10; -
Ceturn ds
End 3un$tion
Publi$ Sub Sa)e_Ce$() !mplements int$om.Sa)e_Ce$
!" $on.State = 4onne$tionState.4losed *&en
$on.5pen()
End !"
2im $md >s (ew SVl4ommand(RinsempR/ $on)
$md.4ommand*7pe = 4ommand*7pe.StoredPro$edure
$md.Parameters.>dd(R]enoR/ SVl2b*7pe.!nt).Value
= p_empno
$md.Parameters.>dd(R]enR/ SVl2b*7pe.Var4&ar/ 1P).
Value = p_ename
$md.Parameters.>dd(R]edR/ SVl2b*7pe.Var4&ar/ 1P).
Value = p_eadd
$md.Parameters.>dd(R]esR/ SVl2b*7pe.!nt).Value
= p_esal
$md.Exe$ute(on\uer7()
$md.2ispose()
$on.4lose()
End Sub
Publi$ Sub Bpdate_Ce$()
!" $on.State = 4onne$tionState.4losed *&en
$on.5pen()
End !"
2im $md >s (ew SVl4ommand(RupdempR/ $on)
$md.4ommand*7pe = 4ommand*7pe.StoredPro$edure
$md.Parameters.>dd(R]enoR/ SVl2b*7pe.!nt).Value
= p_empno
$md.Parameters.>dd(R]enR/ SVl2b*7pe.Var4&ar/ 1P).
Value = p_ename
$md.Parameters.>dd(R]edR/ SVl2b*7pe.Var4&ar/ 1P).
Value = p_eadd
$md.Parameters.>dd(R]esR/ SVl2b*7pe.!nt).Value
= p_esal
$md.Exe$ute(on\uer7()
$md.2ispose()
$on.4lose()
End Sub
Publi$ Propert7 p_eadd() >s String
8et
Ceturn ed
End 8et
- 10A -
Set(#7Val )alue >s String)
ed = )alue
End Set
End Propert7
Publi$ Propert7 p_empno() >s !nteger
8et
Ceturn eno
End 8et
Set(#7Val )alue >s !nteger)
eno = )alue
End Set
End Propert7
Publi$ Propert7 p_ename() >s String
8et
Ceturn en
End 8et
Set(#7Val )alue >s String)
en = )alue
End Set
End Propert7
Publi$ Propert7 p_esal() >s String
8et
Ceturn es
End 8et
Set(#7Val )alue >s String)
es = )alue
End Set
End Propert7
End 4lass
Publi$ 4lass $om"un$tion
Publi$ S&ared Sub 3ill_2ata(#7Val Vr7 >s String/ #7Val ob6 >s
List4ontrol/ #7Val datatext >s String/ #7Val
data)alue >s String)
2im adp >s (ew SVl2ata>dapter(Vr7/
R2ata#ase=dbemplo7ee;uid=saR)
2im ds >s (ew 2ataSet
adp.3ill(ds)
ob6.2ata*ext3ield = datatext
ob6.2ataValue3ield = data)alue
ob6.2ataSour$e = ds
ob6.2ata#ind()
End Sub
- 10B -
End 4lass
End (amespa$e
I De!au#t.as"/.cs
!mports S7stem.2ata
Partial 4lass _2e"ault
!n&erits S7stem.Aeb.B!.Page
2im ob6 >s (ew nsemp.$lsemp
Prote$ted Sub Page_Load() .andles 'e.Load
End Sub
Prote$ted Sub #utton1_4li$%()
ob6.p_empno = 4on)ert.*o!nt+,(*ext#ox1.*ext)
ob6.p_ename = *ext#ox,.*ext
ob6.p_eadd = *ext#ox+.*ext
ob6.p_esal = *ext#ox0.*ext
ob6.Sa)e_Ce$()
*ext#ox1.*ext = RR
*ext#ox,.*ext = RR
*ext#ox+.*ext = RR
*ext#ox0.*ext = RR
End Sub
Prote$ted Sub #utton,_4li$%() .andles #utton,.4li$%
ob6.p_empno = 4on)ert.*o!nt+,(*ext#ox1.*ext)
ob6.2elete_Ce$()
*ext#ox1.*ext = RR
*ext#ox,.*ext = RR
*ext#ox+.*ext = RR
*ext#ox0.*ext = RR
End Sub
Prote$ted Sub #utton+_4li$%() .andles #utton+.4li$%
ob6.p_empno = 4on)ert.*o!nt+,(*ext#ox1.*ext)
ob6.p_ename = *ext#ox,.*ext
ob6.p_eadd = *ext#ox+.*ext
ob6.p_esal = *ext#ox0.*ext
ob6.Bpdate_Ce$()
*ext#ox1.*ext = RR
*ext#ox,.*ext = RR
*ext#ox+.*ext = RR
*ext#ox0.*ext = RR
End Sub
Prote$ted Sub #utton0_4li$%() .andles #utton0.4li$%
- 10: -
nsemp.$om"un$tion.3ill_2ata(Rsele$t E "rom tbempR/
List#ox1/ RenameR/ RempnoR)
End Sub
Prote$ted Sub List#ox1_Sele$ted!ndex4&anged()
ob6.p_empno = 4on)ert.*o!nt+,(List#ox1.Sele$ted!ndex)
2im ds >s (ew 2ataSet()
ds = ob6.3ind_re$()
2im r >s 2ataCowView
r = ds.*ables(P).2e"aultView(P)
*ext#ox1.*ext = r(P).*oString()
*ext#ox,.*ext = r(1).*oString()
*ext#ox+.*ext = r(,).*oString()
*ext#ox0.*ext = r(0).*oString()
End Sub
End 4lass
DATABA). 9ANDLIN4 WIT9 CLA)) =C8.Net>
A"" (ebcon#ig #ie an" a cass #ie
Pace A te-tbo-s , A button an" a istbo- AutoPostBac= true
using S7stem.2ata.SVl4lient;
namespa$e nsemp
{
publi$ inter"a$e int$om
{
)oid Sa)e_Ce$();
)oid Bpdate_Ce$();
)oid 2elete_Ce$();
2ataSet 3ind_re$();
publi$ inter"a$e intemp
{
!nt+, p_empno
{
get;
set;
- 10@ -
!nt+, p_sal
{
get;
set;
String p_ename
{
get;
set;
String p_eadd
{
get;
set;
publi$ abstra$t $lass $ls$on
{
prote$ted SVl4onne$tion $on = new SVl4onne$tion();
publi$ $ls$on()
{
$on.4onne$tionString = 4on"iguration'anager.
4onne$tionStrings9R$sR:.4onne$tionString;
publi$ $lass $lsemp @ $ls$on/ int$om/ intemp
{
//$e define interface after comma and to impliment them right clic( on it n clic(
implement interface
pri)ate !nt+, eno/ es;
pri)ate String en/ ed;
Uregion intemp 'embers
publi$ int p_empno
{
get
{
return eno;
set
{
eno = )alue;
- 10N -
publi$ int p_sal
{
get
{
return es;
set
{
es = )alue;
publi$ string p_ename
{
get
{
return en;
set
{
en = )alue;
publi$ string p_eadd
{
get
{
return ed;
set
{
ed = )alue;
Uendregion
Uregion int$om 'embers
publi$ )oid Sa)e_Ce$()
{
i" ($on.State == 4onne$tionState.4losed)
{
$on.5pen();
- 10O -
SVl4ommand $md = new SVl4ommand(RinsempR/ $on);
$md.4ommand*7pe = 4ommand*7pe.StoredPro$edure;
$md.Parameters.>dd(R]enoR/ SVl2b*7pe.!nt).Value
= p_empno;
$md.Parameters.>dd(R]enR/ SVl2b*7pe.Var4&ar/
1P).Value = p_ename;
$md.Parameters.>dd(R]edR/ SVl2b*7pe.Var4&ar/
1P).Value = p_eadd;
$md.Parameters.>dd(R]esR/ SVl2b*7pe.!nt).Value
= p_sal;
$md.Exe$ute(on\uer7();
$md.2ispose();
$on.4lose();
publi$ )oid Bpdate_Ce$()
{
i" ($on.State == 4onne$tionState.4losed)
{
$on.5pen();
SVl4ommand $md = new SVl4ommand(RupdempR/ $on);
$md.4ommand*7pe = 4ommand*7pe.StoredPro$edure;
$md.Parameters.>dd(R]enoR/ SVl2b*7pe.!nt).Value
= p_empno;
$md.Parameters.>dd(R]enR/ SVl2b*7pe.Var4&ar/
1P).Value = p_ename;
$md.Parameters.>dd(R]edR/ SVl2b*7pe.Var4&ar/
1P).Value = p_eadd;
$md.Parameters.>dd(R]esR/ SVl2b*7pe.!nt).Value
= p_sal;
$md.Exe$ute(on\uer7();
$md.2ispose();
$on.4lose();
publi$ )oid 2elete_Ce$()
{
i" ($on.State == 4onne$tionState.4losed)
{
$on.5pen();
SVl4ommand $md = new SVl4ommand(RdelempR/ $on);
$md.4ommand*7pe = 4ommand*7pe.StoredPro$edure;
$md.Parameters.>dd(R]enoR/ SVl2b*7pe.!nt).Value
= p_empno;
$md.Exe$ute(on\uer7();
- 110 -
$md.2ispose();
$on.4lose();
publi$ 2ataSet 3ind_re$()
{
SVl2ata>dapter adp = new
SVl2ata>dapter(R"indempR/ $on);
adp.Sele$t4ommand.Parameters.>dd(R]enoR/
SVl2b*7pe.!nt).Value = p_empno;
adp.Sele$t4ommand.4ommand*7pe =
4ommand*7pe.StoredPro$edure;
2ataSet ds = new 2ataSet();
adp.3ill(ds);
return ds;
Uendregion
publi$ $lass $ls$om"un$tion
{
publi$ stati$ )oid "ill_data(String Vr7/List4ontrol
ob6/String datatext/ String data)alue)
{
SVl2ata>dapter adp = new SVl2ata>dapter(Vr7/
4on"iguration'anager.4onne$tionStrings9R$sR:
.4onne$tionString);
2ataSet ds = new 2ataSet();
adp.3ill(ds);
ob6.2ata*ext3ield = datatext;
ob6.2ataValue3ield = data)alue;
ob6.2ataSour$e = ds;
ob6.2ata#ind();
I De!au#t.as"/.cs
publi$ partial $lass _2e"ault @ S7stem.Aeb.B!.Page
{
nsemp.$lsemp ob6 = new nsemp.$lsemp();
prote$ted )oid Page_Load(ob6e$t sender/ E)ent>rgs e)
{
prote$ted )oid #utton1_4li$%()
{
ob6.p_empno = 4on)ert.*o!nt+,(*ext#ox1.*ext);
ob6.p_ename = *ext#ox,.*ext;
- 111 -
ob6.p_eadd = *ext#ox+.*ext;
ob6.p_sal = 4on)ert.*o!nt+,(*ext#ox0.*ext);
ob6.Sa)e_Ce$();
*ext#ox1.*ext = RR;
*ext#ox,.*ext = RR;
*ext#ox+.*ext = RR;
*ext#ox0.*ext = RR;
prote$ted )oid #utton,_4li$%(sender/ e)
{
ob6.p_empno = 4on)ert.*o!nt+,(*ext#ox1.*ext);
ob6.2elete_Ce$();
*ext#ox1.*ext = RR;
*ext#ox,.*ext = RR;
*ext#ox+.*ext = RR;
*ext#ox0.*ext = RR;
prote$ted )oid #utton+_4li$%(sender/ e)
{
ob6.p_empno = 4on)ert.*o!nt+,(*ext#ox1.*ext);
ob6.p_ename = *ext#ox,.*ext;
ob6.p_eadd = *ext#ox+.*ext;
ob6.p_sal = 4on)ert.*o!nt+,(*ext#ox0.*ext);
ob6.Bpdate_Ce$();
*ext#ox1.*ext = RR;
*ext#ox,.*ext = RR;
*ext#ox+.*ext = RR;
*ext#ox0.*ext = RR;
prote$ted )oid #utton0_4li$%(ob6e$t /E)ent>rgs e)
{
nsemp.$ls$om"un$tion."ill_data(Rsele$t E "rom
tbempR/ List#ox1/ RenameR/ RempnoR);
prote$ted )oid List#ox1_Sele$ted!ndex4&anged()
{
ob6.p_empno =
4on)ert.*o!nt+,(List#ox1.Sele$ted!ndex);
2ataSet ds = new 2ataSet();
ds=ob6.3ind_re$();
2ataCowView r;
r=ds.*ables9P:.2e"aultView9P:;
*ext#ox1.*ext = r9P:.*oString();
*ext#ox,.*ext = r91:.*oString();
*ext#ox+.*ext = r9,:.*oString();
*ext#ox0.*ext = r9+:.*oString();
- 112 -
DATABA). 9ANDLIN4 U)IN4 CU)TO6 COLL.CTION
A"" (ebcon#ig #ie an" a cass #ie
using S7stem.2ata.SVl4lient;
using S7stem.4olle$tions.8eneri$; // 5o create custom collection 0array
of ob#ects1
namespa$e nsemp
{
publi$ inter"a$e intemp
{
!nt+, p_empno
{
get;
set;
!nt+, p_esal
{
get;
set;
String p_ename
- 11; -
{
get;
set;
String p_eadd
{
get;
set;
publi$ $lass $lsempprp@intemp
//right clic( to implement interface
{
pri)ate !nt+, eno/ es;
pri)ate String en/ ed;
Uregion intemp 'embers
publi$ int p_empno
{
get
{
return eno;
set
{
eno = )alue;
publi$ int p_esal
{
get
{
return es;
set
{
es = )alue;
publi$ string p_ename
{
get
{
return en;
- 11A -
set
{
en = )alue;
publi$ string p_eadd
{
get
{
return ed;
set
{
ed = )alue;
Uendregion
publi$ abstra$t $lass $ls$on
{
prote$ted SVl4onne$tion $on = new SVl4onne$tion();
publi$ $ls$on()
{
$on.4onne$tionString = 4on"iguration'anager.
4onne$tionStrings9R$sR:.4onne$tionString;
publi$ $lass $lsemp @ $ls$on
{
publi$ )oid sa)e_re$($lsempprp p)
{
i" ($on.State == 4onne$tionState.4losed)
{
$on.5pen();
SVl4ommand $md = new SVl4ommand(RinsempR/ $on);
$md.4ommand*7pe = 4ommand*7pe.StoredPro$edure;
$md.Parameters.>dd(R]enoR/ SVl2b*7pe.!nt).Value
= p.p_empno;
$md.Parameters.>dd(R]enR/ SVl2b*7pe.Var4&ar/
1P).Value = p.p_ename;
- 11B -
$md.Parameters.>dd(R]edR/ SVl2b*7pe.Var4&ar/
1P).Value = p.p_eadd;
$md.Parameters.>dd(R]esR/ SVl2b*7pe.!nt).Value
= p.p_esal;
$md.Exe$ute(on\uer7();
$md.2ispose();
$on.4lose();
publi$ )oid update_re$($lsempprp p)
{
i" ($on.State == 4onne$tionState.4losed)
{
$on.5pen();
SVl4ommand $md = new SVl4ommand(RupdempR/ $on);
$md.4ommand*7pe = 4ommand*7pe.StoredPro$edure;
$md.Parameters.>dd(R]enoR/ SVl2b*7pe.!nt).Value
= p.p_empno;
$md.Parameters.>dd(R]enR/ SVl2b*7pe.Var4&ar/
1P).Value = p.p_ename;
$md.Parameters.>dd(R]edR/ SVl2b*7pe.Var4&ar/
1P).Value = p.p_eadd;
$md.Parameters.>dd(R]esR/ SVl2b*7pe.!nt).Value
= p.p_esal;
$md.Exe$ute(on\uer7();
$md.2ispose();
$on.4lose();
publi$ )oid delete_re$($lsempprp p)
{
i" ($on.State == 4onne$tionState.4losed)
{
$on.5pen();
SVl4ommand $md = new SVl4ommand(RdelempR/ $on);
$md.4ommand*7pe = 4ommand*7pe.StoredPro$edure;
$md.Parameters.>dd(R]enoR/ SVl2b*7pe.!nt).Value
= p.p_empno;
$md.Exe$ute(on\uer7();
$md.2ispose();
$on.4lose();
publi$ List;$lsempprp< 2is_re$()
{
// +ist is a class $hich is used to create custom collection
i" ($on.State == 4onne$tionState.4losed)
{
- 11: -
$on.5pen();
SVl4ommand $md = new SVl4ommand(RdispempR/$on);
$md.4ommand*7pe = 4ommand*7pe.StoredPro$edure;
SVl2ataCeader dr;
dr = $md.Exe$uteCeader();
List;$lsempprp< ob6 = new List;$lsempprp<();
w&ile (dr.Cead())
{
$lsempprp % = new $lsempprp();
%.p_empno = 4on)ert.*o!nt+,(dr9P:);
%.p_ename = dr91:.*oString();
%.p_eadd = dr9,:.*oString();
%.p_esal = 4on)ert.*o!nt+,(dr9+:);
ob6.>dd(%);
dr.4lose();
$md.2ispose();
$on.4lose();
return ob6;
publi$ List;$lsempprp< "ind_re$(!nt+, eno)
{
i" ($on.State ==4onne$tionState.4losed)
{
$on.5pen();
SVl4ommand $md = new SVl4ommand(R"indempR/$on);
$md.4ommand*7pe = 4ommand*7pe.StoredPro$edure;
$md.Parameters.>dd(R]enoR/SVl2b*7pe.!nt).Value
=eno;
SVl2ataCeader dr;
dr = $md.Exe$uteCeader();
List;$lsempprp< ob6 = new List;$lsempprp<();
i"(dr..asCows)
{
dr.Cead();
$lsempprp % = new $lsempprp();
%.p_empno = 4on)ert.*o!nt+,(dr9P:);
%.p_ename = dr91:.*oString();
%.p_eadd = dr9,:.*oString();
%.p_esal = 4on)ert.*o!nt+,(dr9+:);
ob6.>dd(%);
dr.4lose();
$md.2ispose();
- 11@ -
$on.4lose();
return ob6;
Pace #ormvie$
DataMe+&ames %Eem%no
',oose Data source ob5ect "ata source1
7nabe Paging true
Pace ob5ect "ata source1
Dse" $it, ; tier arc,itecture
Stateess 2 a#ter "oing itSs $or= "istr+ t,e connection6
Bin" $it, cass
'ic= on con#igure "ata source o# ob5ect "ata source1
Seect csem%
Seect c,oose met,o" Dis%E)ec
D%"ate c,oose met,o" u%"ateE)ec
!nsert c,oose met,o" saveE)ec
Deete c,oose met,o" DeeteE)ec
Pace List bo-
',oose Data source ob5ect "ata source2
Data<ie" ename
DataVaueem%no
Pace ob5ect "ata source1 con#igure "ata source o# ob5ect "ata source1
Seect csem%
Seect c,oose met,o" Dis%E)ec
Pace anot,er #ormvie$
DataMe+&ames %Eem%no
',oose Data source ob5ect "ata source
7nabe Paging true
Pace ob5ect "ata sourcecon#igure "ata source o# ob5ect "ata source
Seect csem%
Seect c,oose met,o" <in"E)ec
D%"ate c,oose met,o" u%"ateE)ec
!nsert c,oose met,o" saveE)ec
Deete c,oose met,o" DeeteE)ec
'ic= on ne-t
Pass eno #rom contro istbo-1
- 11N -
DLL =Dyamic #ik #i1rary>
'om%ie" casses
)eusabe
Sco%e in muti%e %ro5ects
!n %rocess 2 reGuire" $,ere t,e a%%ication is running6 $,ereas e-e is out %rocess
Part o# '*/ 2com%onent ob5ect mo"e6
!t is a so#t$are arc,itecture $,ic, is use" to "esign a so#t$are com%onent
Sma in si?e as com%are to e-e
<aster as com%are to e-e
DLL o# .net se# "escribe". 2no nee" to register t,e DLL. 4ust co%+ K run it, 'L)
=no$ in $,ic, or"er it $i run K ,o$ it $or=6
Aso cae" as Assembies
1o create it
<ie &e$ Pro5ect cass Librar+
- 11O -
using S7stem.2ata.SVl4lient;
using S7stem.4olle$tions.8eneri$; // 5o create custom collection 0array
of ob#ects1
namespa$e nsemp
{
publi$ inter"a$e intemp
{
!nt+, p_empno
{
get;
set;
!nt+, p_esal
{
get;
set;
String p_ename
{
get;
set;
String p_eadd
{
get;
set;
publi$ $lass $lsempprp@intemp
//right clic( to implement interface
{
pri)ate !nt+, eno/ es;
pri)ate String en/ ed;
Uregion intemp 'embers
publi$ int p_empno
{
get
{
return eno;
set
{
eno = )alue;
- 120 -
publi$ int p_esal
{
get
{
return es;
set
{
es = )alue;
publi$ string p_ename
{
get
{
return en;
set
{
en = )alue;
publi$ string p_eadd
{
get
{
return ed;
set
{
ed = )alue;
Uendregion
publi$ abstra$t $lass $ls$on
{
prote$ted SVl4onne$tion $on = new SVl4onne$tion();
publi$ $ls$on()
{
$on.4onne$tionString = 4on"iguration'anager.
4onne$tionStrings9R$sR:.4onne$tionString;
- 121 -
publi$ $lass $lsemp @ $ls$on
{
publi$ )oid sa)e_re$($lsempprp p)
{
i" ($on.State == 4onne$tionState.4losed)
{
$on.5pen();
SVl4ommand $md = new SVl4ommand(RinsempR/ $on);
$md.4ommand*7pe = 4ommand*7pe.StoredPro$edure;
$md.Parameters.>dd(R]enoR/ SVl2b*7pe.!nt).Value
= p.p_empno;
$md.Parameters.>dd(R]enR/ SVl2b*7pe.Var4&ar/
1P).Value = p.p_ename;
$md.Parameters.>dd(R]edR/ SVl2b*7pe.Var4&ar/
1P).Value = p.p_eadd;
$md.Parameters.>dd(R]esR/ SVl2b*7pe.!nt).Value
= p.p_esal;
$md.Exe$ute(on\uer7();
$md.2ispose();
$on.4lose();
publi$ )oid update_re$($lsempprp p)
{
i" ($on.State == 4onne$tionState.4losed)
{
$on.5pen();
SVl4ommand $md = new SVl4ommand(RupdempR/ $on);
$md.4ommand*7pe = 4ommand*7pe.StoredPro$edure;
$md.Parameters.>dd(R]enoR/ SVl2b*7pe.!nt).Value
= p.p_empno;
$md.Parameters.>dd(R]enR/ SVl2b*7pe.Var4&ar/
1P).Value = p.p_ename;
$md.Parameters.>dd(R]edR/ SVl2b*7pe.Var4&ar/
1P).Value = p.p_eadd;
$md.Parameters.>dd(R]esR/ SVl2b*7pe.!nt).Value
= p.p_esal;
$md.Exe$ute(on\uer7();
$md.2ispose();
$on.4lose();
publi$ )oid delete_re$($lsempprp p)
{
i" ($on.State == 4onne$tionState.4losed)
- 122 -
{
$on.5pen();
SVl4ommand $md = new SVl4ommand(RdelempR/ $on);
$md.4ommand*7pe = 4ommand*7pe.StoredPro$edure;
$md.Parameters.>dd(R]enoR/ SVl2b*7pe.!nt).Value
= p.p_empno;
$md.Exe$ute(on\uer7();
$md.2ispose();
$on.4lose();
publi$ List;$lsempprp< 2is_re$()
{
// +ist is a class $hich is used to create custom collection
i" ($on.State == 4onne$tionState.4losed)
{
$on.5pen();
SVl4ommand $md = new SVl4ommand(RdispempR/$on);
$md.4ommand*7pe = 4ommand*7pe.StoredPro$edure;
SVl2ataCeader dr;
dr = $md.Exe$uteCeader();
List;$lsempprp< ob6 = new List;$lsempprp<();
w&ile (dr.Cead())
{
$lsempprp % = new $lsempprp();
%.p_empno = 4on)ert.*o!nt+,(dr9P:);
%.p_ename = dr91:.*oString();
%.p_eadd = dr9,:.*oString();
%.p_esal = 4on)ert.*o!nt+,(dr9+:);
ob6.>dd(%);
dr.4lose();
$md.2ispose();
$on.4lose();
return ob6;
publi$ List;$lsempprp< "ind_re$(!nt+, eno)
{
i" ($on.State ==4onne$tionState.4losed)
{
$on.5pen();
SVl4ommand $md = new SVl4ommand(R"indempR/$on);
$md.4ommand*7pe = 4ommand*7pe.StoredPro$edure;
$md.Parameters.>dd(R]enoR/SVl2b*7pe.!nt).Value
- 12; -
=eno;
SVl2ataCeader dr;
dr = $md.Exe$uteCeader();
List;$lsempprp< ob6 = new List;$lsempprp<();
i"(dr..asCows)
{
dr.Cead();
$lsempprp % = new $lsempprp();
%.p_empno = 4on)ert.*o!nt+,(dr9P:);
%.p_ename = dr91:.*oString();
%.p_eadd = dr9,:.*oString();
%.p_esal = 4on)ert.*o!nt+,(dr9+:);
ob6.>dd(%);
dr.4lose();
$md.2ispose();
$on.4lose();
return ob6;
6A)T.R *A4.)
<or common a+out on a t,e %ages.
!n 1.1 t,ere $as no master %ages conce%t $e use $eb user contro but in t,is at
ever+ %age co"e co%+ ,ota ,ai.
!n 2.0 t,ere is t$o %ages /aster Page2"esign6, content %age2>1/L6 an" t,e+
combine at run time to ma=e one %age.
1o insert master %age $ebsite A"" ne$ item /aster %age
7-tension o# master %age is T.master
7= %age %ar e= se 5a"a master %age ,o sa=te ,ai
La+out !nsert tabe 1em%ate ,ea"er,#ooterKSi"e
A"" %icture in %ro5ect an" "rag it on ,ea"er
4a,an "esign #i- na,i =arma A"" 'ontent Pace >o"er
/aster Page )un &a,i ,ota $e s,ou" a"" 'ontent %age
A"" A"rotator too to rotate t,e images $,en $e cic= re#res,
- 12: -
1o bin" images in A"rotater a"" X/L #ie or tabe in "atabase
A"rotator %ro%erties
A"vertisement<ie X/L <ie
Me+$or"<iter 1o% 3 bottom
<6L !i#e
;Oxml )ersion=R1.PR en$oding=Rut"LYR O<
;>d)ertisements
xmlns=R&ttp@??s$&emas.mi$roso"t.$om?>sp(et?>dCotator
LS$&eduleL3ileR<
;>d xmlns=RR<
;!mageBrl xmlns=RR<a1.gi";?!mageBrl<
;(a)igateBrl xmlns=RR<de"ault,.aspx;?(a)igateBrl<
;>lternate*ext xmlns=RR<3irst >dd;?>lternate*ext<
;`e7word xmlns=RR<*op;?`e7word<
;!mpressions xmlns=RR<1;?!mpressions<
// impressions is used to tell the ration of add to display
;?>d<
;>d xmlns=RR<
;!mageBrl xmlns=RR<a,.gi";?!mageBrl<
;(a)igateBrl xmlns=RR<de"ault+.aspx;?(a)igateBrl<
;>lternate*ext xmlns=RR<Se$ond >dd;?>lternate*ext<
;`e7word xmlns=RR<*op;?`e7word<
;!mpressions xmlns=RR<,;?!mpressions<
;?>d<
;>d xmlns=RR<
;!mageBrl xmlns=RR<a+.gi";?!mageBrl<
;(a)igateBrl xmlns=RR<de"ault0.aspx;?(a)igateBrl<
;>lternate*ext xmlns=RR<*&ird >dd;?>lternate*ext<
;`e7word xmlns=RR<bottom;?`e7word<
// ?ey$ord is used to tell this add $ill display in $hich "drotator if there is more than
one adrotator
;!mpressions xmlns=RR<1;?!mpressions<
;?>d<
;>d xmlns=RR<
;!mageBrl xmlns=RR<a0.gi";?!mageBrl<
;(a)igateBrl xmlns=RR<de"ault1.aspx;?(a)igateBrl<
;>lternate*ext xmlns=RR<3ourt& >dd;?>lternate*ext<
;`e7word xmlns=RR<bottom;?`e7word<
;!mpressions xmlns=RR<,;?!mpressions<
;?>d<
;?>d)ertisements<
A"" Labe on master %age
1o e-cess t,is abe in 'ontent %age
- 12@ -
publi$ partial $lass 2e"ault, @ S7stem.Aeb.B!.Page
{
prote$ted )oid Page_Load(ob6e$t sender/ E)ent>rgs e)
{
Label lb = (Label)('aster.3ind4ontrol(Rlabel1R));
lb.*ext = RPage,R;
Cotet *a&e
using S7stem.2rawing;
prote$ted )oid Page_Load(ob6e$t sender/ E)ent>rgs e)
{
'aster.p_"$olor = 4olor.Ced;
1o /a=e a menu a"" menu toobar #rom navigator an" bin" it $it,
Site/a%DataSource
/enu is a "ataboun" contro $e must use Site/a%DataSource to bin" a t+%e o#
navigatot toos
Site/a%DataSource ta=es "ata #rom Site/a% #ie $,ic, is a X/L #ie. &o nee" to
bin" it i# t,ere is on+ one Site/a% #ie
- 12N -
)ite6a" Fi#e
A"" it #rom (ebsiteA"" ne$ items Site/a%
;Oxml )ersion=R1.PR en$oding=Rut"LYR O<
;site'ap
xmlns=R&ttp@??s$&emas.mi$roso"t.$om?>sp(et?Site'apL
3ileL1.PR <
;site'ap(ode url=RR title=R'enuR des$ription=R'enuR<
;site'ap(ode url=Rde"ault,.aspxR title=RPage1R
des$ription=RPage1R ?<
;site'ap(ode url=Rde"ault+.aspxR title=RPage,R
des$ription=RPage,R ?<
;site'ap(ode url=RR title=RSub 'enuR
des$ription=RSub menuR<
;site'ap(ode url=Rde"ault0.aspxR
title=Rpage+R<;?site'ap(ode<
;site'ap(ode url=Rde"ault1.aspxR
title=RPage0R<;?site'ap(ode<
;?site'ap(ode<
;?site'ap(ode<
;?site'ap<
Site/a%Pat, %ro%erties
Pat, se%arator YYY
Pat, Direction )oot1o'urrent3'urrent1o)oot
Pat,LeveDis%a+e" -1 2to "is%a+ #u %at,6
)an"er'urrent&oDeAsLin= 1rue
/enu Pro%erties
StaticDis%a+Leves 2
/a-imumD+namicDis%a+Leve ;
!# t,ere are more t,an one Site/a%<ie t,en in $eb.con#ig $rite
;s7stem.web<
;site'ap enabled=RtrueR de"aultPro)ider=Rx7R<
;pro)iders<
;add name=Rx7R t7pe=RS7stem.Aeb.NmlSite'apPro)iderR
site'ap3ile=RAeb.sitemapR?<
;add name=Rx=R t7pe=RS7stem.Aeb.NmlSite'apPro)iderR
site'ap3ile=RAeb,.sitemapR?<
;?pro)iders<
;?site'ap<
1o bin" navigator too $it, secon" Site/a%, in Site/ a%DataSource %ro%erties
Site /a%Provi"er -?
- 12O -
TO U*LOAD FIL. ON ).RV.R
<rom toobo- <ieD%oa"
Pace a button 2u%oa"6
prote$ted )oid #utton1_4li$%(ob6e$t sender/ E)ent>rgs e)
{
String st = 3ileBpload1.Posted3ile.3ile(ame;
// file path at client machine
!nt+, i = st.Last!ndex5"(RFFR);
// IJI used $ith e6cape se&uences thatFs y $e use IJJI
- 1;0 -
st = st.Substring(i - 1);
// st B file name only
//create a upload folder on server to store uploades files
String "p = Ser)er.'apPat&(RuploadsR);
// uploads path
"p = "p - RFFR - st;
3ileBpload1.Posted3ile.Sa)e>s("p);
TO )TOR. I6A4. IN DATABA). IN BINAR; FOR6
'reate a tabe tbimage
image!" int
img&ame image
e-t varc,ar2B06
A"" (eb con#ig #ie
Pace te-tbo- #or i"
Pace <ieu%oa" too an" a button
using S7stem.2ata.SVl4lient;
using S7stem.!5;
- 1;1 -
publi$ partial $lass _2e"ault @ S7stem.Aeb.B!.Page
{
prote$ted )oid #utton1_4li$%(ob6e$t sender/E)ent>rgs e)
{
!nt+, ln;
ln = 3ileBpload1.Posted3ile.4ontentLengt&;
#7te9: ar = new b7te9ln:;
3ileStream "s = new
3ileStream(3ileBpload1.Posted3ile.3ile(ame/
3ile'ode.5pen/ 3ile>$$ess.Cead);
// FileStream is used to read/$rite data in binary format
"s.Cead(ar/ P/ ln L 1);
"s.4lose();
String "n;
"n = 3ileBpload1.Posted3ile.3ile(ame;
String ext;
ext = "n.Substring("n.Last!ndex5"(R.R));
// last)nde6Hf starts Searching from right hand side
SVl4onne$tion $on = new SVl4onne$tion();
$on.4onne$tionString = 4on"iguration'anager.
4onne$tionStrings9R$sR:.4onne$tionString;
$on.5pen();
SVl4ommand $md = new SVl4ommand();
$md.4ommand*ext = Rinsert into tbimage )alues(]id/
]name/ ]ext)R;
$md.4onne$tion = $on;
$md.Parameters.>dd(R]idR/ SVl2b*7pe.!nt).Value =
4on)ert.*o!nt+,(*ext#ox1.*ext);
$md.Parameters.>dd(R]nameR/ SVl2b*7pe.!mage).Value
= ar;
$md.Parameters.>dd(R]extR/ SVl2b*7pe.Var4&ar/
1P).Value = ext;
$md.Exe$ute(on\uer7();
$md.2ispose();
$on.4lose();
To retrie%e it
Pace te-tbo- #or i"
Pace !mage too an" a button
- 1;2 -
prote$ted )oid #utton,_4li$%(ob6e$t sender/ E)ent>rgs e)
{
SVl4onne$tion $on = new SVl4onne$tion();
$on.4onne$tionString = 4on"iguration'anager.
4onne$tionStrings9R$sR:.4onne$tionString;
$on.5pen();
SVl4ommand $md = new SVl4ommand();
$md.4ommand*ext = Rsele$t E "rom tbimage w&ere
image!d=]idR;
$md.4onne$tion = $on;
$md.Parameters.>dd(R]idR/ SVl2b*7pe.!nt).Value =
4on)ert.*o!nt+,(*ext#ox,.*ext);
SVl2ataCeader dr;
dr = $md.Exe$uteCeader();
i" (dr..asCows)
{
dr.Cead();
#7te9: ar = (#7te9:)(dr91:);
// in drCKD id4 drC@D image in binary4 drCLD e6tension
String "n;
String a;
a = 8uid.(ew8uid().*oString();
//Auid Alobal uni&ue identifier
"n = Ser)er.'apPat&(a - dr9,:.*oString());
3ileStream "s = new 3ileStream("n/
3ile'ode.4reate/ 3ile>$$ess.Arite);
"s.Arite(ar/ P/ ar.Lengt& L 1);
"s.4lose();
!mage1.!mageBrl = "n;
dr.4lose();
$md.2ispose();
$on.4lose();
To remo%e !i#es
prote$ted )oid #utton+_4li$%(ob6e$t sender/ E)ent>rgs e)
{
2ire$tor7!n"o dir = new
- 1;; -
2ire$tor7!n"o(Ser)er.'apPat&(R.R));
//I.I MMN !urrent folder other$ise folder name
3ile!n"o "i = dir.8et3iles(RE.gi"[);
"orea$&(3ile!n"o " in "i)
{
"i.2elete(".3ull(ame);
T.6*ORAR; TABL.)
&o insert, u%"ate, seect, "eete Guer+
1,e+ are on cient si"e on+.
!# con#orm, $e can a"" t,em in Database.
!t is 5ust i=e 2D arra+. But #ormatte" i=e tabes in "b
(e can ma=e %rimar+ =e+, #oreign =e+, e-%ression coumns
Pace a 0ri"Vie$
prote$ted )oid Page_Load(ob6e$t sender/ E)ent>rgs e)
- 1;A -
{
2ata*able item = new 2ata*able(RtbitemR);
//9atatable used to create temporary table
2ata4olumn $ = new 2ata4olumn(Ri$odeR/
*7pe.8et*7pe(RS7stem.!nt+,R));
$.>uto!n$rement = true;
$.>uto!n$rementSeed = 1P1;
$.>uto!n$rementStep = 1;
item.4olumns.>dd($);
$ = new 2ata4olumn(RinameR/
*7pe.8et*7pe(RS7stem.StringR));
$.>llow2#(ull = "alse;
item.4olumns.>dd($);
$ = new 2ata4olumn(RirateR/
*7pe.8et*7pe(RS7stem.!nt+,R));
item.4olumns.>dd($);
$ = new 2ata4olumn(RiVt7R/
*7pe.8et*7pe(RS7stem.!nt+,R));
item.4olumns.>dd($);
$ = new 2ata4olumn(RiamtR/
*7pe.8et*7pe(RS7stem.!nt+,R));
$.Expression = RiVt7 E irateR;
item.4olumns.>dd($);
2ata4olumn9: p% = new 2ata4olumn91:;
p%9P: = item.4olumns9P:;
item.Primar7`e7 = p%;
//to add data in table
2ataCow r;
r = item.(ewCow();
r91: = RPenR;
r9,: = 1P;
r9+: = 0;
item.Cows.>dd(r);
r = item.(ewCow();
r91: = RS$aleR;
r9,: = 1;
r9+: = Q;
item.Cows.>dd(r);
r = item.(ewCow();
r91: = R$omputerR;
r9,: = ,1PPP;
r9+: = ,;
- 1;B -
item.Cows.>dd(r);
r = item.(ewCow();
r91: = RLaptopR;
r9,: = QPPPP;
r9+: = 1;
item.Cows.>dd(r);
8ridView1.2ataSour$e = item;
8ridView1.2ata#ind();
*ext#ox1.*ext = item.4ompute(RSum(iamt)R/
null).*oString();
// null is for filter or $e can $rite condition li(e IiamtNOKKI
Re#atio o! Ta1#es
prote$ted )oid Page_Load(ob6e$t sender/ E)ent>rgs e)
{
2ata*able dep = new 2ata*able(RtbdepR);
dep.4olumns.>dd(new 2ata4olumn(RdnoR/
*7pe.8et*7pe(RS7stem.!nt+,R)));
dep.4olumns.>dd(new 2ata4olumn(RdnameR/
*7pe.8et*7pe(RS7stem.StringR)));
2ataCow r;
r = dep.(ewCow();
r9P: = 1;
r91: = R!n"ormation *e$&nolog7R;
dep.Cows.>dd(r);
r = dep.(ewCow();
r9P: = ,;
r91: = R4i)ilR;
dep.Cows.>dd(r);
r = dep.(ewCow();
r9P: = +;
r91: = REle$troni$sR;
dep.Cows.>dd(r);
r = dep.(ewCow();
r9P: = 0;
r91: = REle$tri$alR;
- 1;: -
dep.Cows.>dd(r);
2ata*able emp = new 2ata*able(RtbempR);
emp.4olumns.>dd(new 2ata4olumn(RempnoR/
*7pe.8et*7pe(RS7stem.!nt+,R)));
emp.4olumns.>dd(new 2ata4olumn(RenameR/
*7pe.8et*7pe(RS7stem.StringR)));
emp.4olumns.>dd(new 2ata4olumn(ReaddR/
*7pe.8et*7pe(RS7stem.StringR)));
emp.4olumns.>dd(new 2ata4olumn(ResalR/
*7pe.8et*7pe(RS7stem.!nt+,R)));
emp.4olumns.>dd(new 2ata4olumn(RednoR/
*7pe.8et*7pe(RS7stem.!nt+,R)));
//Foreign (ey
2ata4olumn $1 = emp.4olumns90:;//!hild
2ata4olumn $, = dep.4olumns9P:;//;arent
2ataSet ds = new 2ataSet();
ds.*ables.>dd(emp);
ds.*ables.>dd(dep);
2ataCelation rel = new 2ataCelation(Rm7relationR/
$,/ $1);
ds.*ables9P:.ParentCelations.>dd(rel);
//"l$ays child ma(e a relation $ith parent not vice versa
r = emp.(ewCow();
r9P: = 1;
r91: = R>mitR;
r9,: = R>mbalaR;
r9+: = ,PPPP;
r90: = 1;
emp.Cows.>dd(r);
r = emp.(ewCow();
r9P: = 1;
r91: = R>mitR;
r9,: = R>mbalaR;
r9+: = ,PPPP;
r90: = ,;
emp.Cows.>dd(r);
// 8nter edno dno $hich is available in dep table only other$ise error
- 1;@ -
A)).6BLI.)
DLL is =no$n as Assemb+ in .&et 'o? DLL is S%eci#ic to 'L).
Assembies are ogic units, Data Structure
!t is 5ust an in#ormation reGuire" at run time to e-ecute an a%%ication
/ani#est contain in#ormation about Assembies
/ani#est is a grou% o# /eta"ata tabes
/eta"ata tabes are o# t$o t+%es
'ustom Assemb+ 2$,ic, $e create6
Pre"e#ine
- 1;N -
1+%es o# Assembies
Private Assembies
S,are Assembies
Sateite Assembies
DLL are Private assembies 2co%+ in Bin <o"er6
S,are Assemb+
Singe co%+ s,are b+ muti%e user
Dse ess s%ace on server
( can create muti%e versions $it, t,e ,e% o# Strong &ame
Strong &ame
DniGueness "e#ine =arta ,ai
/uti%e versions store =arta ,ai
!t uses ,as,ing tec,niGue =no$n as Pubic Me+ 'r+%togra%,+
/uti%e versions are maintain b+ 0oba Assemb+ 'ac,e 20A'6
0A' is avaiabe at '.H$in"o$sHAssemb+H...
Sateite Assembies is use" to create site in muti%e anguages2>in"i, 7ngis,6
!# DLL Pro5ect me a"" ,o 5a+e to, $o, Private ,ai ot,er$ise S,are" ,ai.
To create )hare !i#e
Start A Programs /s Visua Stu"io 200B Visua Stu"io toos Visua
Stu"io 'omman" Prom%t
'"H
'" 'assLibrar+1
'" 'assLibrar+1
'" ob5
'" Debug
Sn F= abc.sn=
5o $rite in output file
Strong /ame command
!n 'assLibrar+ cass1.cs soution e-%orer %ro%erties
Assemb+!n#o.cs
!n ast $rite
UAssemb+. Assemb+Me+<ie28abc.sn=96V an" com%ie it
!n 'omman" %rom%t $rite
Y 0acDti -! 'assLibrar+1
'o%+ to 0A'
0A' utiit+ 2to a"" version in 0A'6
&o$ A"" DLL in %ro5ect
(ebsite A"" re#erence bro$se cassLibrar+1 ob5 "ebug DLL #ie
- 1;O -
!# u $ant to c,ange in DLL #ie 5ust ma=e it in same #ie t,en com%ie it an"
again give a strong name an" c,ange t,e name in Assemb+!n#o #ie n t,en
a"" to 0A'.
Dser using o"er version $i get on+ o" met,o"s but ne$ user get a
met,o"s
To create )ate##ite Assem1#y
1o c,ec= t,e anguage o# bro$ser
!nternet 7-%orer toos !nternet o%tions anguages
'o"es
7ngis, ------ en-us
<renc, ------- #r-be
0erman ------ "e-at
!n ne$ $ebsite a"" ne$ te-t #ie
(ebsite a"" ne$ items te-t #ie
<ie name abc.en-us.t-t
//Where abc is base name4 en is culture4 us is region
A"" one more te-t #ie
<ie name abc.#r-be.t-t
A"" one more te-t #ie
<ie name abc."e-at.t-t
!n 1e-t<ie abc.en-us.t-t
A Z (ecome
B Z 7ngis,
' Z Language
D Z DS
!n 1e-t<ie abc.#r-be.t-t
A Z ,b5g5
B Z <renc,
' Z gc,g,gcv
D Z ,v5v5,+
!n 1e-t<ie abc."e-at.t-t
A Z ,bb=5bc="
B Z 0erman
' Z g+c"a=cb
D Z c,"i,c"n
1o convert te-t #ie into resource #ie goto comman" %rom%t o# .&et
'.H$ebsiteHresgen abc.en-us.t-t abc.en-us.resources
'.H$ebsiteHresgen abc.#r-be.t-t abc.#r-be.resources
'.H$ebsiteHresgen abc."e-at.t-t abc."e-at.resources
!n a resource #ie
- 1A0 -
o $e can store
Bit ma%
!cons
'ommon messages
o 1,e+ are com%ie"
o 'om%resse" "ata
!n %age %ace Dro%Do$nList
o 7"it !tems
1e-t 7ngis,
Vaue en-us
1e-t <renc,
Vaue #r-be
1e-t 0erman
Vaue "e-at
A"" 0oba A%%ication cass
o 0oba.asa-
o 7= %ro5ect me e= ,i ,o sati ,ai
o 1o manage a%%ication ans session events
;G] !mport (amespa$e=RS7stem.Cesour$esR G<
;G] !mport (amespa$e=RS7stem.*&readingR G<
;G] !mport (amespa$e=RS7stem.8lobali=ationR G<
;s$ript runat=Rser)erR<
)oid >ppli$ation_Start(ob6e$t sender/ E)ent>rgs e)
{
// !ode that runs on application startup
// yeh cod e( hi baar fire hota hai
>ppli$ation9RabR: = Cesour$e'anager.
4reate3ile#asedCesour$e'anager
(Rab$R/ Ser)er.'apPat&(R.R)/ null);
// application varible0Alobal4 used by all files1
// yeh $ohi resources file uthaiga #is(a base name IabcI hoga
// select Begin:e&uest event of "pplication
prote$ted )oid >ppli$ation_#eginCeVuest(ob6e$t/ E)ent>rgs)
{
- 1A1 -
// #itni baar page server par #ata hai yeh event fire hota hai
tr7
{
*&read.4urrent*&read.4urrent4ulture=new 4ulture!n"o
(CeVuest.BserLanguages9P:.*oString());
$at$&
{
*&read.4urrent*&read.4urrent4ulture = new
4ulture!n"o(RenLusR);
*&read.4urrent*&read.4urrentB!4ulture =
*&read.4urrent*&read.4urrent4ulture;
Co$i&
using S7stem.Cesour$es;
using S7stem.*&reading;
// $e use threads co% $e dont $ant to change the language of bro$ser but the language
of current instance of bro$ser
using S7stem.8lobali=ation;
// in this there is culture specfic classes
publi$ partial $lass _2e"ault @ S7stem.Aeb.B!.Page
{
Cesour$e'anager rm;
prote$ted )oid Page_Load(ob6e$t sender/ E)ent>rgs e)
{
rm = (Cesour$e'anager)(>ppli$ation9RabR:);
i" (Page.!sPost#a$% == "alse)
{
Label1.*ext = rm.8etString(R>R);
Label,.*ext = rm.8etString(R#R);
Label+.*ext = rm.8etString(R4R);
Label0.*ext = rm.8etString(R2R);
pri)ate )oid Set4ul(String d)
{
*&read.4urrent*&read.4urrentB!4ulture = new
4ulture!n"o(d);
// change language of current thread
Label1.*ext = rm.8etString(R>R);
Label,.*ext = rm.8etString(R#R);
Label+.*ext = rm.8etString(R4R);
Label0.*ext = rm.8etString(R2R);
- 1A2 -
prote$ted )oid 2rop2ownList1_Sele$ted!ndex4&anged()
{
Set4ul(2rop2ownList1.Sele$tedValue);
)tate 6aa&emet
'ommon in a $eb "eveo%ment anguage i=e P>P, .net, 5ava.
- 1A; -
(eb <orm are stateess in nature $,ic, means $,en reGuest goes to server %ages
oose t,eir in#ormation i=e registration #orm oose "ata $,en $e come bac=.
State management tec,niGues ,ave been intro"uce" to store %age in#ormation in
server aroun" tri%.
1ec,noog+ "ivi"e" into t$o %arts
o Server si"e state management tec,niGue
!t uses resources o# server to store in#ormation
Secure as t,e in#ormation is on server.
So$.
o 'ient si"e state management tec,niGue
!t uses resources o# cient to store in#ormation.
!t ess secure as com%are to server si"e co? it is at cient si"e user can
mani%uate or "eete it.
!t is #aster t,an server si"e.
A tec,noog+ incu"e" in cient si"e state management
o 'oo=ies
o Vie$ state
o Quer+ string
o >i""en #ie"s
o 'ontro state 2in As%.&et 2.0 on+6
A tec,noog+ incu"e" in server si"e state management
o Sessions
o A%%ication
o Pro#ie 2in As%.&et 2.0 on+6
o 'ac,e
1o c,ec= t,ere %er#ormance $e c,ec= t,ree t,ings accor"ing to our reGuirement
o Storing ca%acit+
o 1+%e o# in#ormation
o Sco%e
C#iet )i$e )tate 6aa&emet
Cookies
o !t is a sma te-t #ie create" on cientSs mac,ine $,ic, is use" to store te-t as
$e as number.2$e can store on+ string vaue not ob5ects6
o 1$o t+%es o# coo=ies
!m%ersistence coo=ies 2tem%orar+6
1,ese are "estro+e" as soon as bro$ser is cose"
Persistence
(,ic, e-%ire a#ter a s%eci#ic time s%eci#ie" b+ %rogrammer.
o 'oo=ies store
- 1AA -
!m%ersistence coo=ies in bro$ser memor+
Persistence coo=ies in coo=ies #o"er
2Document K settingusernamecoo=ies6
o !t can store A0O: b+tes 2A=b6 o# "ata internet e-%orer but "e%en"ent on
bro$ser or on version.
o !nitia si?e o# a coo=ie is B0 b+tes 2!n $,ic, e-%ir+ "ate3time is store6
o (e can restrict coo=ies accor"ing to %at,
o 'oo=ies are D)L s%eci#ic $,ic, means +a,oo $ai gmai %er use na,i ,ogi.
o A $eb site can create ma-imum 20 coo=ies
o 'oo=ies e-%ir+ "ate3time is o# server not o# cient.
o A coo=ie can store in#ormation in #orm o# =e+ vaue %airs.
o !t is use" $,en $e $ant to store more t,an one in#ormation in a coo=ie but $e
s,ou" manage it %ro%er+ $it, =e+ vaue.
o Disa"vantage
'ients can "isabe on ,is3,er coo=ies #ies.
So it is not reiabe $,ic, means $e are not sure t,at it $i run on
cient mac,ine or not.
Si?e imitation
Dser can mani%uate
Some bro$sers "onSt su%%ort coo=ies.
o Sco%e
1,oug, out t,e $ebsite, on a t,e %ages o# $ebsite.
o (or=ing
*n ever+ reGuest coo=ies goes to server $,ere t,ere e-%ir+ "ate3time
is c,ec=e"
entries o# coo=ies e-%ire t,en te-t #ie is aso "eete"
Sub=e+
&o initia s%ace
Attac, $it, coo=ie
1,ere is no e-%ir+ "ate3time, "estro+ $it, coo=ie on+
&amevaue'oection cass is use" to rea" sub=e+ vaue
1o rea" sub=e+ name $e use AMe+s 2arra+ o# =e+s6
View )tate 2incu"e" in .net on+6
o 7ver+ $eb%age contain a ,i""en #ie" name as 8E Evie$state9 $,ic, is
%rovi"e" b+ /icroso#t.
o 8E EVie$State store in#ormation as muti%e =e+ %airs 2as arra+6
o !t stores in#ormation in ,aste" 2it ,e%s in "ata retrieving #aster6, com%resse"
#orm an" enco"e".
o 7ver+ $eb server contro ,as %ro%ert+
enabeVie$State 2b+ "e#aut it is true6 $,en it is true contro be#ore
%osting to server store t,ere in#ormation in E Evie$State
- 1AB -
o vie$State variabe can store te-t, number as $e as ob5ect.
o !t is eas+ to use 5ust set 7nabeVie$State %ro%ert+ eit,er to 1rue or <ase
o (e can s%eci#+ encr+%tion mo"e, %age si?e in version 2.0
o Page si?e b+ "e#aut is -12unimite"6 $e can s%eci#+ b+tes.
o Disa"vantage
Large voume o# "ata =e case me %er#ormance is so$
o Sco%e
'urrent %age on+.
:uery )tri&
o !t is use" to trans#er te-t as $e as numeric in#ormation bet$een continues
%age reGuests.2string vaue on+6
o 1,e in#ormation is concentrate" $it, D)L.
o Disa"vantage
!n#ormation can be seen b+ user so not so secure
!nternet D)L imit 220O: c,aracters6
o Sco%e
D%to ne-t %age.
9i$$e Fie#$
o A"vance o# ,i""en #ie"s is vie$ state
o !n t,is $e can on+ store te-t not ob5ect
o Sco%e
*n+ on current %age
Cotro# )tate
o !n t,is custom contro 2ma"e b+ %rogrammer6 =i state management ,oti ,ai
)er%er )i$e )tate 6aa&emet
A""#icatio
o (,en #irst user site =,ota ,ai A%%ication Start event #ire ,ota ,ai
o A%%ication Start event e= ,i baar #ire ,ota ,ai.
o (,en anot,er user site =,ota ,ai >11P A%%ication cass =a instance
banta ,ai.
o A%%ication 7n" event tab #ire ,ota ,ai 5ab ast visitor site ban" =arta ,ai,
+e, event b,i e= ,i bar #ire ,ota ,ai. 4ab +e, #ire ,ota ,ai is=e baa"
A%%ication Start event #ire ,ota ,ai.
o A%%ication variabe can be string as $e as ob5ects
- 1A: -
o Sco%e -- 1,oug,t-out t,e a%%ication
o A%%ication variabe sab,i user =e i+e same ,ota ,ai.
o >it counter2 to vie$ visitors6 is e-am%e o# t,is state management
)essio
o Server generates 2 co%ies o# uniGue session!".
o *ne co%+ on cient si"e2in session coo=ie6 ot,er on server si"e2memor+6
o !n .&et $e can create coo=ie ess a%%ication t,en t,ere is Quer+String in
D)L.
o Session!"Ss engt, is 12N bits.
o Session e-%ir+ time b+ "e#aut is 20 min. $e can c,ange it.
o Session.Aven"on #orce#u+ e-%ires t,e session, incu"ing $,en bro$ser is
cose".
o !# $e o%en a ne$ $in"o$ t,en $e get t,e same session!"
o 1+%es o# Session State
!n %rocess 2B+ De#aut6
1o store session in same %rocess $,ere a%%ication is
running
Dra$bac=s
o !# $e reset t,e $ebserver session automatica+
"estro+s t,atSs + $e cant use" t,is in secure sites
*ut %rocess
1o store session on "i##erent %rocess
A"vantage
o !# $e reset t,e server session "estro+ na,i ,ote.
/o"es
o State server
1o store session on "i##erent server
&ote. 1o im%ement t,is $e must start
ASP.&et State Service.
!# $e reset ASP.&et State Service Session
"estro+ ,o 5ate ,ai.
o SQL Server
(e store session in SQL "atabase
1$o t+%e o# s+stem "e#ine "atabase
1em% Db
o !# $e reset SQL server
service t,en 1em% Db =a "ata
"eete ,o 5ata ,ai
As% State
o Qe "ata %ermanent ,ai.
o *ut %rocess =e case me session en" event #ie na,i ,ota.
- 1A@ -
*ro!i#e
o 1o set coors, t,emes , bac= groun" etc "i##erent #or "i##erent users.
o 1$o t+%es o# users
Aut,enticate" 2in=a %ro#ie ASP.&et "b me store ,ota ,ai6
Dnaut,enticate" 2in=a coo=ies me store ,ota ,ai6
Cookies
Pace t$o te-tbo-es an" a button
prote$ted )oid #utton1_4li$%(ob6e$t sender/ E)ent>rgs e)
{
i" (*ext#ox1.*ext == Rab$R II *ext#ox,.*ext == Rx7=R)
{
.ttp4oo%ie $% = new .ttp4oo%ie(Rm7$%%R);
$%.Values.>dd(RunameR/ *ext#ox1.*ext); // sub(ey
$%.Values.>dd(RupassR/ *ext#ox,.*ext); // sub(ey
$%.Expires = 2ate*ime.(ow.>dd'inutes(+P);
// if u donFt specify the e6piry time then coo(ie $ill destroy as soon as u
close the bro$ser
// or u can specify this li(e
//ck.Expires=DateTime.Now.Add(new TimeSpan(3,45,35));
// Phr <Omin POsec
Cesponse.4oo%ies.>dd($%);
Cesponse.Cedire$t(Rde"ault,.aspxR);
A"" ne$ %age an" %ace t$o te-tbo-es, a abe an" a button
prote$ted )oid #utton1_4li$%(ob6e$t sender/ E)ent>rgs e)
{
.ttp4oo%ie % = CeVuest.4oo%ies9Rm7$%%R:;
i" (% == null)
{
Label1.*ext = R$oo%ies not $reatedR;
else
{
i" (%.Values9RunameR:.*oString() == *ext#ox1.*ext II
%.Values9RupassR:.*oString() == *ext#ox,.*ext)
{
Label1.*ext = Rwel$omeR;
else
- 1AN -
{
Label1.*ext=R$&e$% username I passwordR;
/////////////////////////////////////////////////////////////
Cesponse.4oo%ies9RunR:.Value = Rab$R;
Cesponse.4oo%ies9RunR:.Expires =
2ate*ime.(ow.>dd.ours(,);
/////////////////////////////////////////////////////////////
.ttp4oo%ie %% = new .ttp4oo%ie(RunR/ Rab$R);
%.Expires = 2ate*ime.(ow.>dd.ours(,);
Cesponse.4oo%ies.>dd(%);
/////////////////////////////////////////////////////////////
//!oo(ies $ith sub (eys
/////////////////////////////////////////////////////////////
Cesponse.4oo%ies9RuiR:9RunR: = Rab$R;
Cesponse.4oo%ies9RuiR:9RupR: = Rx7=R;
Cesponse.4oo%ies9RuiR:.Expires =
2ate*ime.(ow.>dd.ours(,);
///////////////////////////////////////////////////////////
.ttp4oo%ie %%% = new .ttp4oo%ie(RuiR);
%%%.Value9RunR: = Rab$R;
%%%.Value9RupR: = Rx7=R;
%%%.Expires = 2ate*ime.(ow.>dd.ours(,);
Cesponse.4oo%ies.>dd(%%%);
////////////////////////////////////////////////////////////
// 5o :ead Value//
///////////////////////////////////////////////////////////
Cesponse.Arite(CeVuest.4oo%ies9RunR:.Value);
///////////////////////////////////////////////////////////
.ttp4oo%ie d = CeVuest.4oo%ies9RunR:;
Cesponse.Arite(d.Value);
//////////////////////////////////////////////////////////
- 1AO -
// 5o read Sub ?ey
//////////////////////////////////////////////////////////
Cesponse.Arite(CeVuest.4oo%ies9RuiR:
9RunR:.*oString());
Cesponse.Arite(CeVuest.4oo%ies9RuiR:9RupR:.*oString());
/////////////////////////////////////////////////////////
.ttp4oo%ie VV = CeVuest.4oo%ies(RuiR);
Cesponse.Arite(VV.Value9RunR:.*oString);
Cesponse.Arite(VV.Value9RupR:.*oString);
///////////////////////////////////////////////////////
// 5o print all the !oo(ies and thire value
///////////////////////////////////////////////////////
!nt+, i;
"or (i = P; i ; CeVuest.4oo%ies.4ount; i--)
{
.ttp4oo%ie a = CeVuest.4oo%ies9i:;
i" (a..as`e7s)
{
S7stem.4olle$tions.Spe$iali=ed.
(ameValue4olle$tion n);
n) = a.Values;
// "rray ban #ayega values (a
String9: ar = a.Values.>ll`e7s;
// Sub (eys (e name (a array
!nt+, 6;
"or (6 = P; 6 ; n).4ount; 6--) ;
{
Cesponse.Arite(RSub `e7 (ame@R-ar96:.
*oString()-RValue@R-n)96:.
*oString() - R;br<R);
///////////////////////////////////////////////////////////
// 5o restrict for path
//////////////////////////////////////////////////////////
%%.Pat& = RadminR;
// this coo(ie $or( $ith admn folder only
- 1B0 -
:uery)tri&
Pace 2 te-tbo-es an" one button
prote$ted )oid #utton1_4li$%(ob6e$t sender/ E)ent>rgs e)
{
Cesponse.Cedire$t(Rde"ault,.aspxOab=R-*ext#ox1.*ext
- RIab1=R-*ext#ox,.*ext);
// use IQI phele variable (e sath aur I2I rest (e sath
2e"ault,.aspx
Pace a abe an" one button
prote$ted )oid Page_Load(ob6e$t sender/ E)ent>rgs e)
{
Label1.*ext = RAel$ome@R -
CeVuest.\uer7String9RabR:.*oString() -
CeVuest.\uer7String9Rab1R:.*oString();
- 1B1 -
To O"e Ca#e$er i "o"u" wi$ow
Pace a te-tbo- an" a button
;&ead runat=Rser)erR<
;title<Bntitled Page;?title<
;s$ript language=6a)as$ript<
"un$tion ab$(id)
{
window.open(Rde"ault,.aspxOab=R-id/RnameR/
R&eig&t=+1P/widt&=+1PR);
// 5o open sub Windo$
;?s$ript<
;?&ead<
2e"ault.aspx.$s
prote$ted )oid Page_Load(ob6e$t sender/ E)ent>rgs e)
{
#utton1.>ttributes.>dd(R5n4li$%R/
Rab$(D"orm1.textbox1D);R);
2e"ault,.aspx
Pace a caen"er contro
'aen"er Da+)en"er event
prote$ted 4alendar1_2a7Cender(ob6e$t/2a7CenderE)ent>rgs)
{
??3ire "or ea$& da7
e.4ell.4ontrols.4lear();
.tml8eneri$4ontrol l% = new .tml8eneri$4ontrol();
?? `isi b&i tag %a %aam %arwa sa%te &ai
l%.*ag(ame = RaR;
l%.!nner*ext = e.2a7.2a7(umber*ext;
l%.>ttributes9R&re"R: =
String.3ormat(R6a)as$ript@window.
- 1B2 -
opener.do$ument.{P.)alue=D{1D;window.$lose()R/
CeVuest.\uer7String9RabR:.*oString()/
e.2a7.2ate.*oS&ort2ateString());
e.4ell.4ontrols.>dd(l%);
- 1BA -
*ae# o same scree
Pace A %ane an" %ace buttons on t,em &e-t an" %rev
prote$ted )oid Page_Load(ob6e$t sender/ E)ent>rgs e)
{
i" (Page.!sPost#a$% == "alse)
{
ViewState9R$trR: = 1;
Panel1.Visible = true;
Panel,.Visible = "alse;
Panel+.Visible = "alse;
Panel0.Visible = "alse;
- 1BB -
!n source #ie a"" *n'ic= $it, Prev an" &e-t button
(ext #utton 5n4li$%=R#tn_(extR
Pre) #utton 5n4li$%=R#tn_Pre)R
A""#icatio =9it Couter>
A"" &e$ !tem 0oba A%%ication 'ass
)oid >ppli$ation_Start(ob6e$t sender/ E)ent>rgs e)
{
// !ode that runs on application startup
>ppli$ation9R$trR: = P;
)oid Session_Start(ob6e$t sender/ E)ent>rgs e)
{
// !ode that runs $hen a ne$ session is started
>ppli$ation.Lo$%();
>ppli$ation9R$trR: =
4on)ert.*o!nt+,(>ppli$ation9R$trR:) - 1;
>ppli$ation.BnLo$%();
2e"ault.aspx.$s
prote$ted )oid Page_Load(ob6e$t /E)ent>rgs)
{
Label1.*ext = >ppli$ation9R$trR:.*oString();
1o c,ec= t,e no. o# user current+ using t,is site
)oid Session_End(ob6e$t sender/ E)ent>rgs e)
{
// !ode that runs $hen a session ends.
// /oteR 5he SessionG8nd event is raised only $hen the sessionstate mode
// is set to )n;roc in the Web.config file. )f session mode is set to StateServer
// or S*+Server4 the event is not raised.
>ppli$ation.Lo$%();
>ppli$ation9R$trR: =
4on)ert.*o!nt+,(>ppli$ation9R$trR:) L 1;
>ppli$ation.BnLo$%();
- 1B: -
)essio
!# u $ant to use one ob5ect t,oug,out t,e session use session ob5ect an" i# u $ant
to use one ob5ect on+ one one %age use a%%ication.
Pace a button
using S7stem.2ata.SVl4lient;
prote$ted )oid #utton1_4li$%(ob6e$t/ E)ent>rgs e)
{
SVl2ata>dapter adp = new SVl2ata>dapter(Rsele$tE
"rom tbempR/ Rdatabase=dbemp;uid=saR);
2ataSet ds = new 2ataSet();
adp.3ill(ds);
Session9RssR: = ds;
Cesponse.Cedire$t(Rde"ault,.aspxR);
2e"ault,.aspx
Pla$e a grid)iew I a button
prote$ted )oid Page_Load(ob6e$t / E)ent>rgs e)
{
8ridView1.2ataSour$e = (2ataSet)(Session9RssR:);
8ridView1.2ata#ind();
prote$ted )oid #utton1_4li$%(ob6e$t/ E)ent>rgs e)
{
Session.>bandon();
// 5o e6pire session forcefully
)essio )tate
!nProcess2B+ "e#aut6
*utProcess
- 1B@ -
Start !!S server #rom contro %ane a"" remove #ies $in"o$s
com%onents
*%en ne$ a%%ication
Seect Location >tt% , name ,tt%.33Loca,ost3aaa
Pace Button
prote$ted )oid #utton1_4li$%(ob6e$t / E)ent>rgs e)
{
Session9RssR: = R&elloR;
Cesponse.Cedire$t(Rde"ault,.aspxR);
2e"ault,.aspx.$s
Pace abe
prote$ted )oid Page_Load(ob6e$t/ E)ent>rgs e)
{
i" (Session9RssR: K= null)
{
Label1.*ext = Session9RssR:.*oString();
else
{
Label1.*ext = R(o 2ataR;
To reset We1 ser%er
0oto visua stu"io comman" %rom%t
1+%e --- iisreset 2"ata in in%roc $i ost6
Out *rocess
)tate )er%ice
A"" $eb con#ig #ie
;s7stem.web<
;sessionState mode=RStateSer)erR
state4onne$tionString=Rt$pip=1,Q.P.P.1@0,0,0R
timeout=R,PR<;?sessionState<
- 1BN -
State server uses As%.net State Service
1o start it
'ontro Pane A"ministrator 1oo Services As%.&etStateService
)ig,t 'ic= start
!# $e reset t,is service $e $i ost t,e session
):L )er%er
!n (eb 'on#ig $rite
;s7stem.web<
;sessionState mode=RS\LSer)erR
sVl4onne$tionString=Rser)er=$s;uid=saR<
;?sessionState<
!t uses t$o "atabases
1em%Db
ASPStateDb
1o te "atabase
!n .&et comman" mo"e
<or 1em%Db
As%netEregsG.e-e FS sac F7 Fssa"" -sst+%e t
<or ASPStateDb
As%netEregsG.e-e FS sac F7 Fssa"" -sst+%e %
(,ere.
-S server
sac server name
-7 current user instance
-D a"min FP %ass$or" 2i# user is se%ec#ice"6
-ssa"" session state a"" "atabase
-sst+%e session state t+%e
1 tem%orar+
P %ermanent
!n 1em%Db "ata is store in ASPState1em%Sessions an" i# $e reset
SQLServerService "ata $i ost
!n ASPStateDb "ata is %ermanent.
- 1BO -
)ho""i& Cart
De!au#t.as"/
Pace DataList, SGDataSource an" con#igure it
Dataist Pro%erties re%eat'oumns 2
!n source
;!tem*emplate<
;b<*itle@;?b<;asp@Lin%#utton *ext=;GUE)al(Rboo%*itleR)G<
4ommand(ame=RSele$tR
runat=Rser)erR<;?asp@Lin%#utton<;br ?<
;b<>ut&or@;?b<;GUE)al(R#oo%>ut&orR)G<;br ?<
;asp@!mage#utton !2=Rimg1R !mageBrl=RM?go_login.gi"R
4ommand(ame=R4artR runat=Rser)erR ?<
;?!tem*emplate<
Set DatMe+<ie" boo=!"
prote$ted )oid 2ataList1_Sele$ted!ndex4&anged(ob6e$t/ e)
{
Cesponse.Cedire$t(R2e"ault,.aspxObid=R -
2ataList1.2ata`e7s92ataList1.Sele$ted!ndex:.
*oString());
- 1:0 -
De!au#t+.as"/
Pace a DetaiVie$
;3ields<
;asp@*emplate3ield .eader*ext=R!dR<
;!tem*emplate<
;asp@Label !2=RLabel1R runat=Rser)erR *ext=D;GU
E)al(Rboo%!dR) G<D<
;?asp@Label<
;?!tem*emplate<
;?asp@*emplate3ield<
;asp@*emplate3ield .eader*ext=R*itleR<
;!tem*emplate<
;asp@Label !2=RLabel,R runat=Rser)erR
*ext=D;GU E)al(Rboo%*itleR) G<D<
;?asp@Label<
;?!tem*emplate<
;?asp@*emplate3ield<
;asp@*emplate3ield .eader*ext=R>ut&orR<
;!tem*emplate<
;asp@Label !2=RLabel+R runat=Rser)erR
*ext=D;GU E)al(Rboo%>ut&orR) G<D<
;?asp@Label<
;?!tem*emplate<
;?asp@*emplate3ield<
;asp@*emplate3ield .eader*ext=RPublis&erR<
;!tem*emplate<
;asp@Label !2=RLabel0R runat=Rser)erR
*ext=D;GU E)al(R#oo%PubR) G<D<
;?asp@Label<
;?!tem*emplate<
;?asp@*emplate3ield<
;asp@*emplate3ield .eader*ext=RPri$eR<
;!tem*emplate<
;asp@Label !2=RLabel1R runat=Rser)erR
*ext=D;GU E)al(R#oo%Pri$eR) G<D<
;?asp@Label<
;?!tem*emplate<
;?asp@*emplate3ield<
;asp@*emplate3ield<
;!tem*emplate<
;asp@#utton !2=R#utton1R runat=Rser)erR
5n4li$%=R#utton1_4li$%R *ext=R#uttonR ?<
;?!tem*emplate<
;?asp@*emplate3ield<
- 1:1 -
;?3ields<
using S7stem.2ata.SVl4lient;
publi$ partial $lass 2e"ault, @ S7stem.Aeb.B!.Page
{
prote$ted )oid Page_Load(ob6e$t sender/ E)ent>rgs e)
{
String st = RSele$t E "rom tb#oo% w&ere boo%!d=R -
CeVuest.\uer7String9RbidR:.*oString();
SVl2ata>dapter adp=new SVl2ata>dapter(st/
4on"iguration'anager.4onne$tionStrings9R$sR:.
4onne$tionString);
2ataSet ds = new 2ataSet();
adp.3ill(ds);
2etailsView1.2ataSour$e = ds;
2etailsView1.2ata#ind();
prote$ted )oid 2etailsView1_!tem4ommand(ob6e$t/ e)
{
prote$ted )oid #utton1_4li$%(ob6e$t / E)ent>rgs e)
{
Cesponse.Cedire$t(Rde"ault+.aspxObid=R -
((Label)(2etailsView1.3ind4ontrol(Rlabel1R))).*ext);
De!au#t?.as"/
Pace 0ri"Vie$
;asp@8ridView !2=R8ridView1R runat=Rser)erR
>uto8enerate4olumns=R3alseR
5nCow4an$elingEdit=R8ridView1_Cow4an$elingEditR
5nCow2eleting=R8ridView1_Cow2eletingR
5nCowEditing=R8ridView1_CowEditingR
5nCowBpdating=R8ridView1_CowBpdatingR<
;4olumns<
;asp@#ound3ield 2ata3ield=Rord!dR .eader*ext=R!dR
Cead5nl7=R*rueR ?<
;asp@#ound3ield 2ata3ield=Rord*itR .eader*ext=R*itleR
Cead5nl7=R*rueR ?<
;asp@#ound3ield 2ata3ield=Rord>ut&orR
- 1:2 -
.eader*ext=R>ut&orR Cead5nl7=R*rueR ?<
;asp@#ound3ield 2ata3ield=RordPubR
.eader*ext=RPublis&erR Cead5nl7=R*rueR ?<
;asp@#ound3ield 2ata3ield=RordPri$eR
.eader*ext=RPri$eR Cead5nl7=R*rueR ?<
;asp@#ound3ield 2ata3ield=Rord\t7R
.eader*ext=R\uantit7R ?<
;asp@#ound3ield 2ata3ield=Rord>mtR .eader*ext=R>mountR
Cead5nl7=R*rueR ?<
;asp@4ommand3ield S&owEdit#utton=R*rueR ?<
;asp@4ommand3ield S&ow2elete#utton=R*rueR ?<
;?4olumns<
;?asp@8ridView<
using S7stem.2ata.SVl4lient;
publi$ partial $lass 2e"ault+ @ S7stem.Aeb.B!.Page
{
prote$ted )oid Page_Load(ob6e$t sender/ E)ent>rgs e)
{
i" (Session9Rss1R: == null)
{
2ata*able tb = new 2ata*able(R*ableR);
tb.4olumns.>dd(new 2ata4olumn(Rord!dR/
*7pe.8et*7pe(RS7stem.!nt+,R)));
tb.4olumns.>dd(new 2ata4olumn(Rord*itR/
*7pe.8et*7pe(RS7stem.StringR)));
tb.4olumns.>dd(new 2ata4olumn(Rord>ut&orR/
*7pe.8et*7pe(RS7stem.StringR)));
tb.4olumns.>dd(new 2ata4olumn(RordPubR/
*7pe.8et*7pe(RS7stem.StringR)));
tb.4olumns.>dd(new 2ata4olumn(RordPri$eR/
*7pe.8et*7pe(RS7stem.!nt+,R)));
tb.4olumns.>dd(new 2ata4olumn(Rord\t7R/
*7pe.8et*7pe(RS7stem.!nt+,R)));
tb.4olumns.>dd(new 2ata4olumn(Rord>mtR/
*7pe.8et*7pe(RS7stem.!nt+,R)));
tb.4olumns9Rord>mtR:.Expression=
Rord\t7EordPri$eR;
Session9Rss1R: = tb;
i" (Page.!sPost#a$% == "alse)
{
String st;
st = Rsele$t E "rom tbboo% w&ere boo%id=R -
CeVuest.\uer7String9RbidR:.*oString();
SVl2ata>dapter adp = new SVl2ata>dapter(st/
- 1:; -
4on"iguration'anager.4onne$tionStrings9R$sR:.
4onne$tionString);
2ataSet ds = new 2ataSet();
adp.3ill(ds);
2ataCowView r; // for one ro$
r = ds.*ables9P:.2e"aultView9P:;
2ata*able ab = (2ata*able)(Session9Rss1R:);
2ataCow r1 = ab.(ewCow();
r19P: = 4on)ert.*o!nt+,(r9Rboo%!dR:);
r191: = r9Rboo%*itleR:.*oString();
r19,:=r9Rboo%>ut&orR:.*oString();
r19+: = r9R#oo%PubR:.*oString();
r190:=4on)ert.*o!nt+,(r9R#oo%Pri$eR:);
r191: = 1;
ab.Cows.>dd(r1);
8ridView1.2ataSour$e = ab;
8ridView1.2ata#ind();
publi$ )oid 8rd#ind()
{
8ridView1.2ataSour$e = (2ata*able)(Session9Rss1R:);
8ridView1.2ata#ind();
prote$ted )oid 8ridView1_CowEditing(ob6e$t sender/ e)
{
8ridView1.Edit!ndex = e.(ewEdit!ndex;
8rd#ind();
prote$ted )oid 8ridView1_CowBpdating(ob6e$t sender/ e)
{
2ata*able tt = (2ata*able)(Session9Rss1R:);
tt.Cows9e.Cow!ndex:91: = 4on)ert.*o!nt+,(((*ext#ox)
(8ridView1.Cows9e.Cow!ndex:.4ells91:.
4ontrols9P:)).*ext);
8ridView1.Edit!ndex = L1;
8rd#ind();
prote$ted )oid 8ridView1_Cow4an$elingEdit(ob6e$t/ e)
{
8ridView1.Edit!ndex = L1;
8rd#ind();
- 1:A -
).CURIT;
Securit+ incu"e
1. Aut,ori?ation means %ermission to user.
2. Aut,entication
Aut,entication o# !!S
1. Basic Aut,entication !n basic aut,entication user %ass$or" store" into ceare"
te-t.
2. Digest Aut,entication1,is aut,entication is b+ "e#aut %rovi"e" b+ !!S an" user
%ass$or" store" in encr+%te" #orm.
;. (in"o$ !ntegrating Aut,enticationDser o# $in"o$.
Aut,entication 1+%es
1. (in"o$ Aut,entication!t is b+ "e#aut aut,entication.
2. <orms
2a6. <orms Aut,entication !t is customi?e" aut,entication an" use" most+.
;. Pass%ort Aut,entication $it, singe sign in $e can ogin into muti%e %ass%ort
7nabe sites.
A. &one
(e can aso create user an" %ass$or" in $ebcon#ig an" -m #ie.
/embers,i% an" roe is a ne$ #eature in 2.0
FOR6 AUT9.NTICATION
1.A"" $ebcon#ig #ie
Dsername
Pass$or" Button
We1co!i& !i#e
Xaut,entication mo"eZ\<orms\Y
X#orms nameZ\coo=ie\ oginDrZ\ogin.as%-\YX3#ormsY
- 1:B -
X3aut,enticationY
Lo&i.as"/
using S+stemR
using S+stem.DataR
using S+stem.'on#igurationR
using S+stem.'oectionsR
using S+stem.(ebR
using S+stem.(eb.Securit+R
using S+stem.(eb.D!R
using S+stem.(eb.D!.(eb'ontrosR
using S+stem.(eb.D!.(eb'ontros.(ebPartsR
using S+stem.(eb.D!.>tm'ontrosR
%ubic %artia cass ogin . S+stem.(eb.D!.Page
I
%rotecte" voi" PageELoa"2ob5ect sen"er, 7ventArgs e6
I
J
%rotecte" voi" Button1E'ic=2ob5ect sen"er, 7ventArgs e6
I
i# 21e-tBo-1.1e-t ZZ \#aisa\ KK 1e-tBo-2.1e-t ZZ \=,an\6
I
<ormsAut,entication.)e"irect<romLoginPage
21e-tBo-1.1e-t,#ase6R
J
ese
I
)es%onse.(rite2\(rong user3%ass$or"\6R
J
J
J
FormsAutheticatio.Re$irectFromLo&i*a&e=Te/tBo/0.Te/t@!a#se>user name =o
coo=ie mai i=,ega aur re"irect to "e#aut %age.
De!au#t.as"/
La1e#
using S+stemR
using S+stem.DataR
using S+stem.'on#igurationR
using S+stem.(ebR
- 1:: -
using S+stem.(eb.Securit+R
using S+stem.(eb.D!R
using S+stem.(eb.D!.(eb'ontrosR
using S+stem.(eb.D!.(eb'ontros.(ebPartsR
using S+stem.(eb.D!.>tm'ontrosR
%ubic %artia cass EDe#aut . S+stem.(eb.D!.Page
I
%rotecte" voi" PageELoa"2ob5ect sen"er, 7ventArgs e6
I
i# 2Dser.!"entit+.!sAut,enticate"6
I
Labe1.1e-t Z \(ecome .\ C Dser.!"entit+.&ameR
J
ese
I
<ormsAut,entication.)e"irect1oLoginPage26R
J
J
J
9OW U).R AUT9.NTICAT. IN W.B CONFI4 FIL.
We1co!i& !i#e
Xaut,entication mo"eZ\<orms\Y
X#orms nameZ\coo=ie\ oginDrZ\ogin.as%-\Y
Xcre"entias %ass$or"<ormat Z\'ear\Y
Xuser name Z\a"min\ %ass$or" Z\a"\3Y
Xuser name Z\a"min1\ %ass$or" Z\a"1\3Y
X3cre"entiasY
X3#ormsY
X3aut,enticationY
Lo&i.as"/
Dsername
Pass$or" Button2
%rotecte" voi" Button2E'ic=2ob5ect sen"er, 7ventArgs e6
I
i# 2<ormsAut,entication.Aut,enticate21e-tBo-1.1e-t,
1e-tBo-2.1e-t66
I
<ormsAut,entication.)e"irect<romLoginPage21e-tBo-1.1e-t,
- 1:@ -
#ase6R
J
ese
I
)es%onse.(rite2\(rong user3%ass$or"\6R
J
J
)"eci!ic Autherity
X3s+stem.$ebY
Xocation %at, Z\"e#aut2.as%-\Y
Xs+stem.$eb Y
Xaut,ori?ation Y
Xao$ users Z\a"min\3Y
X"en+ users Z\T\3Y
X3aut,ori?ationY
X3s+stem.$ebY
X3ocationY
Xocation %at, Z\"e#aut;.as%-\Y
Xs+stem.$eb Y
Xaut,ori?ation Y
Xao$ users Z\a"min1\3Y
X"en+ users Z\T\3Y
X3aut,ori?ationY
X3s+stem.$ebY
X3ocationY
T /eans "en+ aut,erisation an" unaut,erisation user.
P /eans "en+ unaut,enticate".
De!au#t.as"/
+ hy"er#ik 1utto
Pro%ert+&avigationD)LDe#aut2.as%-
Pro%ert+&avigationD)LDe#aut;.as%-
- 1:N -
ROL. BA).D ).CURIT;
'reate tabe t1usr
Dname varc,ar2B06
D%ass varc,ar2B06
Droe varc,ar2B06
A"" some recor" eg
Dname D%ass Droe
<aisa =,an a"min
Sac,in gu%ta user
',aru satia a"min]user
A"" 2 #o"er in soution e-%orer
A"m--Y "e#aut2.as%-,"e#aut;.as%-
Dsr--Y"e#autA.as%-,"e#autB.as%-
Ro#es assi& to !o#$er i we1co!i&!i#e
A"" $ebcon#ig #ie
Xaut,entication mo"eZ\<orms\Y
X#orms nameZ\coo=ie\ oginDrZ\ogin.as%-\Y
X3#ormsY
X3aut,enticationY
X3s+stem.$ebY
Xocation %at, Z\a"m\Y
Xs+stem.$eb Y
Xaut,ori?ation Y
Xao$ roes Z\a"min\3Y
X"en+ users Z\T\3Y
X3aut,ori?ationY
X3s+stem.$ebY
X3ocationY
Xocation %at, Z\usr\Y
Xs+stem.$eb Y
Xaut,ori?ation Y
Xao$ roes Z\user\3Y
X"en+ users Z\T\3Y
- 1:O -
X3aut,ori?ationY
X3s+stem.$ebY
X3ocationY
Lo&i.as"/
Dsername
Pass$or" Button
using S+stem.Data.SG'ientR
%ubic %artia cass ogin1 . S+stem.(eb.D!.Page
I
%rotecte" voi" PageELoa"2ob5ect sen"er, 7ventArgs e6
I
J
%rotecte" voi" Button1E'ic=2ob5ect sen"er, 7ventArgs e6
I
SG'onnection con Z ne$ SG'onnection26R
con.'onnectionString Z \"atabaseZem%Rui"Zsa\R
con.*%en26R
SG'omman" cm" Z ne$ SG'omman"26R
cm".'omman"1e-t Z \seect T #rom tbaut,1 $,ere unameZ[u an" u%assZ[%\R
cm".Parameters.A""2\[u\, SGDb1+%e.Var',ar, B06.Vaue Z1e-tBo-1.1e-tR
cm".Parameters.A""2\[%\, SGDb1+%e.Var',ar, B06.Vaue Z1e-tBo-2.1e-tR
cm".'onnection Z conR
SGData)ea"er "rR
"r Z cm".7-ecute)ea"er26R
i# 2"r.>as)o$s6
I
"r.)ea"26R
<ormsAut,entication1ic=et t=t Z ne$
<ormsAut,entication1ic=et21, 1e-tBo-1.1e-t,
Date1ime.&o$, Date1ime.&o$.A""/inutes2106, #ase,
"rU2V.1oString26, <ormsAut,entication.<orms'oo=iePat,6R
33>ere $e encr+%t t,e tic=et n store" st2tic=et6 an" coo=ie name #rom
$ebcon#ig #ie into coo=ie or $it, t,e ,e% o# Guer+string %asse" t,is vaue
into "e#aut.as%-
- 1@0 -
string stR
st Z <ormsAut,entication.7ncr+%t2t=t6R
>tt%'oo=ie c= Z ne$
>tt%'oo=ie2<ormsAut,entication.<orms'oo=ie&ame, st6R
)es%onse.'oo=ies.A""2c=6R
)es%onse.)e"irect2\"e#aut.as%-\6R
J
ese
I
)es%onse.(rite2\$rong user3%ass$or"\6R
J
"r.'ose26R
cm".Dis%ose26R
J
J
<ormsAut,entication1ic=et t=t 1ic=et is use" #or %assing customise "ata
$,atever $e $ant.
1
st
Parameter is tic=et version no. assign $it, muti%e tic=ets.
2
n"
Parameter username.
;
r"
Parameter issue" tic=et "atetime
A
t,
Parameter e-%ire time
B
t,
Parameter coo=ies tem%2#ase6 or %ermanent2unti $eb bro$ser session
e-%ire6.
:
t,
Parameter string user"ata "rU2V contain tabe cooumn Droe.
@
t,
Parameter string coo=ies %at,.
9ow autheticate user access the !i#e so a A$$ &#o1a# a""#icatio c#ass
4#o1a# A""#icatio C#ass
&ames%ace S+stem.Securit+.Princi%a contain generic %rinci%a cass $,ic, is
combination o# i"entit+ K roes is =no$n as generic %rinci%a.
Seect a%%ication an" ,is event Aut,enticate)eGuest .
7vent Aut,enticate)eGuest #ire ever+ time #or user c,ec=.
>tt%'onte-t7ncu%uate a ,tt% s%eci#ic in#ormation about an in"ivi"ua ,tt% reGuest.
- 1@1 -
XW[ A%%ication LanguageZ\'#\ WY
XW[ !m%ort &ames%ace Z\S+stem.Securit+.Princi%a\WY
Xscri%t runatZ\server\Y
voi" A%%icationEStart2ob5ect sen"er, 7ventArgs e6
I
33 'o"e t,at runs on a%%ication startu%
J
voi" A%%icationE7n"2ob5ect sen"er, 7ventArgs e6
I
33 'o"e t,at runs on a%%ication s,ut"o$n
J
voi" A%%icationE7rror2ob5ect sen"er, 7ventArgs e6
I
33 'o"e t,at runs $,en an un,an"e" error occurs
J
voi" SessionEStart2ob5ect sen"er, 7ventArgs e6
I
33 'o"e t,at runs $,en a ne$ session is starte"
J
voi" SessionE7n"2ob5ect sen"er, 7ventArgs e6
I
33 'o"e t,at runs $,en a session en"s.
33 &ote. 1,e SessionE7n" event is raise" on+ $,en t,e sessionstate mo"e
33 is set to !nProc in t,e (eb.con#ig #ie. !# session mo"e is
set to StateServer
33 or SQLServer, t,e event is not raise".
J
%rotecte" voi" A%%icationEAut,enticate)eGuest2ob5ect sen"er,7ventArgs e6
I
i# 2>tt%'onte-t.'urrent.Dser^Z nu6
I
<orms!"entit+ #iR
77We &et curret user i$etity=ticket>
#i Z 2<orms!"entit+62Dser.!"entit+6R
<ormsAut,entication1ic=et t=R
t= Z #i.1ic=etR
774et user ro#e with ticket@ s"#it the ro#e a$ store$ ito array.
string u" Z t=.DserDataR
stringUV ar Z u".S%it2L]L6R
77!i cotai i$etity o! user a$ array ar cotai ro#e which is kow as
&eeric "rici"a#.
>tt%'onte-t.'urrent.Dser Z ne$ 0enericPrinci%a2#i, ar6R
J
J
X3scri%tY
- 1@2 -
De#aut.as%-
2 >+%erin= Button
Pro%ert+&avigationD)La"m3De#aut2.as%-,De#aut;.as%-
Pro%ert+&avigationD)Lusr3De#autA.as%-,De#autB.as%-
- 1@; -