You are on page 1of 6

SEL Data Reader:

*. Jhis class us used to ead data Brom the &L seAver datalase
Heady data Cn the forwand direction le) once it eads a

Secord,t wwtll cthen Head the next


-ondy
ecod.
*t u cannection - oriented It euener an open oh active eonnection
ute the data SNce uuhile eodung the data.
#.Pata Reade is ead oniey
Popoter:
st s not pessible to
ehanqe the data

1. Connection:
the Sql lonnection asociated with the SolDataReader
&t qets
2.Depth: fby the w.
dt qett a ualue that ndicatek the depth oy
3. Isosed :
Hetsievek Js9olean value Jthat Endícates wthetne the

Sbecifted SaLReade instance has een elosed.


4: RecordsAHected :
ett the number changed, inseted deleted
the exeLtiorn o the Statement.

MOthods:

Clo ses the SaDataReaden chje ct


2. Readc):
It advancex the Sa,lata Reade to cthe next HECONd and
tue there ae mate

Stud ent Tasle :

1d Name Email Mobile


101 Aag Aruag@gmail com 1234561840
102Piganka Pryanta @gmail orm ja876943210
103 Preety pseety @gmail-com (22324 455
Sarm bit Samiit@amail om 018273645

Systen;
wsing ystem- Data. slclient;
namespace AdoNet (onsce Applicai on

UTLC1a
cass Progham
static Vgd Main

sbing Consuving =data souHce .; data base = Student DB;


= SSPI;

Wsing (Saconnection connection =new sqlconrection (Con Sthing))


Sql Command cmd =new Salommand ( " selet Name, Email ,
Mobile from Student Cen necton) ;

connection. Open O;
Sa,1Data Reader sdr = cmd. Exeute ReaderC);
while (sdr. Read C))

Consale. WAiteLine (sdr"Name"]+


sdY ["Mobile ]);

catch ( ExCeptten e)

Console. wtte Linec"omething went

yhen to wse?

a)dange Data Retieval


b) Read-only Opexation
c) seamtng Data
d) aow lateny
e) Perfomance
f) Netwok agticienay
9) Resouce manaq ement
SEL Data Adapter:
clas a sct o saL ommand and a
k. It çs a that epresents
databae connecton.
*. It Us wsed te the Dataset o Data Taute and up date the

datasece.
Constuctors :

a) SqlData Adapter )
b) SlData Adaple (sllommand selectiommand)
) SyiData Adaptes (sting select CommandText , stng select ConrectionSirm)
) a1Data Adapteu (sting select Command Text , alConnection select Connectton)
MethodK:
a) Dispose (Boolean)
t is used to discard the maraqed esancek .
5) FUl ( Dataset):
dt wsed te add eUy ñn the DOtaset t match tho ce in

the data SoAce.


) etfiu ParametesC);
t cs Wsed te qet the patam etexs set the Wser wh en
SELECT
executing n SeL Statement
d) lpdate (tateSet) :
It ik sed to Cal the sespective inset ,update celete state ments.

Student Table:

Id Name Emal Mobile

Anuag Arnag@gmail or 123y sbT890


Pruypnka Priyanko@qmail. con qs76 543210
Poe ety peety @qnail. om o611946854
Saumbit Sombit@qmail.con oq1821364s
Lsing syotem ;
usng system. Data,
Data. Sa Cient;
namespace AdoNet Console Applucation

clas Progam
static
vaid Main (stringti gs)

= @ dota sooce = ITUOtl -19\S6LEKPRESS; database =

StudentDB; nteqrated secwuty ssPT';

using (Sgltonnection connection =new alonnection (ConString)


SalData Adap le cla :new SalData Adapte (" select tom
Student ", onnection) ;
Data Tate ddt = new Dota Talec);
da. Fll (dt );
Console wite Line("Uing Data Tae")
foe acn (Data Row YDW un dt. Rouss)

Console .vteLine (90w"Name "]" " nw"EmaiLT +


"+ DwMobtle);

Dataset ds =new Dtasetc):


da. Fill Cds, "Student ");
Console. WsiteLine C" Utng Data Set");
foreach(Data Row DW un ds.Tables[student "J.Rours )

Console. Wuiteline(w[" Name ]+""+rDw["Email ] + ,


+ YDwMobile ]) ;

3
J coutcn ( EKCeption e)

Console. wtteLine (" went wong)


Example Proqran uiing SalDataReader and daptor:
Sal Dato A

utng aystem ;
Uscng system. Data;
ucng system Data. SqlClient ;
class PAo gham

Static
sthing cone ction Stuing data seusce =ITUll -19 \SQL Express ; dalabak =
Student DB, integrated secusity - sSPT 1
static veid
Main (StLingi angs)
Using (&ay lConne ctten connectian : new sy (onnection (onne ctio n&aing))

connection . Openc);
breatestudentsTalle cuonnection);
Inset Stude nt(connecticn,"Inisha, 2u 5DD6Qnec. edu-in ", IT)i
Console- walteLine ("List cf Students : ");
Dlsplay AIIStudents (onne ctis n);
3
catch ( Exceptron e)
Console. WitelineC"EnoY+ e.

vold Create StudentsTate (SalConnecion connection)


Static

TABLE IE NOT EXISTS Students (


reate Table uexy "CREATE
sting Name nvacha (i00), email nvconchaul io0)
StudertIp int
pimay oy Depatnent nvacha cs))";

ubtng ( Sl Com mand command =new sa lommand Coeate Tableauey>


Connection))

{
Command. tyele
NonQueug))
3
staic vsld InseuStudent CSllonnectio n connetion, Stuing name, sUing
email , 8tuing depament)
: "INSE RT INTO Students (Name, Emall , Depantment)
stng VALUES(@Name, @ mail, @Depatment)";

using CSql ommand ommand =new Sallormnand (unseitauety , onnection )


comnmand.TuameteYs . 4ddWith Vale C"@Name', name);
Command.Parameteys. Addwitn ValueC@EmaiL, email);
ommand.Paiameters. Add withVallle ('@Depatment, de partment );
command. Exeate Non bueay
3
connection)
Stattc vsld Dspay AlIStudents (sl onn ection
selectOuey =sELECT FROM Students ";
wsing (salcommand ommand - nGw Sq (lommand (seled6uey , connection))

Wing (Sal Data Reades eader ommand. Exeate ReadercO)

shile (Aeades Read())

name ID- Header. yetInt 32 Co);


uing name : keadea. yetstingci,
emall: neader. qetSting c2),
Ctug depts Acader Getsuing (3);
Console. walte Line (4"tp :{ name ID} , Namef namey ,
Emalt : femaüt3 , Depautment : (dep t} ");

You might also like