0% found this document useful (0 votes)
5 views

.NET-2nd Unit

ADO.NET is a framework for data access in .NET applications, allowing interaction with databases through a set of objects and methods. It includes components like DataSet, DataReader, and DataAdapter, which facilitate connected and disconnected data access. ADO.NET enhances performance and reduces development time by providing a structured way to manage data operations.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

.NET-2nd Unit

ADO.NET is a framework for data access in .NET applications, allowing interaction with databases through a set of objects and methods. It includes components like DataSet, DataReader, and DataAdapter, which facilitate connected and disconnected data access. ADO.NET enhances performance and reduces development time by providing a structured way to manage data operations.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 18

Unik-2

ADo NET
ADo means Ackive Data objecks
EVeny oganiz at con maintains data
Shomage foy tb busine ss, emplayes and
clienks.
Tha dota must be easiy accesik le
and updakable
The sewane used to cneake and
SExe he dakabases js Called back
end , HS Acce SS . Sel Se Ven Ce Ehe
Iponkart back end selhoone
The machine in which Ehe dta
end back
database is skoe d is
known s
benver
Data in a daka base Can not be
a

accesse d die cky by Wse

IE Can be
accessed thnugh Bomne
Special s Fwuone called nlend
opplica iors
visu al Basic, VB NET
ront end Lools
ae
he impes
Tis database Can be accessed and
Csed by fnont end opplicat tons th nough some
Conec)ivjes
The machine nin which the applicatns
is known a client
Corne c)ch ivit is aa kechnology Usedl bo
make a Connec ton bekween 4ront end b
back end applicahon.
Fo a Long Eime 0DBc ((open Data Base
onnechi vta)has beon Used that allows
opplicat con o acceS S ony data soce
eihen Local b memot e
The tunch oins ODBC includes adding,
moditying and doa Eing data and ob aining
de ails about databases and tables
Now a dayp, Hic oseg t intoduced a
Aet o progiarmmalle objects Knoun as
Povidos data
Ackive pala object (ADo hat
access bernvice buch that all bypes
data Can be acce%e d
ADO iS detined as
as object model
cun

that USes be o object metRac


Popeties The melhods in ADD Ab: e USed

o wBas acces s and pdate the Lhe data


Soun ce Such as sal dalabawes nd oLEDB
dat abase properis ae Used Lo Cont
dhe behoyib uy e< mnethods
Data aCCess Usinq ADo jn Ehe NET
Plattom Ts Khown as ADoNET IE
Eypicaly reduces devalepment ime , Code
Size and provides excellent perfoman ce.
feakuner e ADO NET
Thene cMe
ve ve 4eatioes ADo NET.
They
L. Data Access
2. Data Reador
3. Data Set
H 'ndependent o databas e
5. XHL Coded Pa La
Data Access -
In the eanhen client -s enVen oppieatona
a Connechion to database Js Kept
open il he applicat wh is unning
Ths decmeases the ovena l)
llous
applicatton Penoimance, ADo NET
|o twok wikh data tn a Connected
O1 distonnec ke d node
In he Conneckedl ode, the opplicadion
ulk.
issues a que y and hocess Lhe res
In khe dstonnected mode, theen d
database is sent o Ehe ron losed
aplicatclon and he onneckus u
Aten ll fhe upd at Lons OVer the
database is sent back o the data
bounce

Reader (Data Reade)


Cormmnicate
pata e ader allous Lo
dababase in Connecked mode. The
with
tunct on dota teader includos
Procedres,
urning quenies, unning
cbjecta and porfoming
Creatíng dakabase objecls
DDL Commands

DataSet
Dataset is a Fempo SkoMegf data
twy Vinkual
like a
1e Comcls 7t wDHks
a

Contains the eny Ubed


Skotage hat database Jt allous the
1e cotcs om database
applicat LÕn o woMk with a
mocle
in disonneched
Independent Dababase
Dalaset doos not have any elat ten
So i Can Contain
ship wth the database.
databases
data nom multiple
XNL Code d data
în ADo .NET , dat a is Lons<enmed o
om data base to dataset in the toom
XHL do tument The use need not krcw
XHL n ADo NET- I± utomotically Convods
data nto XHL and ice Vesa.
Achitechuse e ADO NE1
Achitectoye e ADo NET iS a
ollection clawsos, obects, methods and
Porop orfes that manage data access
om telat tonal dakabases with in the
-NET plat fosn
These ollections Osganize d in
Ehe nanmes paces sytem . pata System
Data. OleDb cnd sptem. Pata Salelient
ADo -NET provides two cenbtal
Component .NET Daka poviderr and
Dota Set.
The tiquHe shown below iluskorats
he anchitec e o ADo NET
Dataset
Data Table collechon
-NET Data providot
Dota Table
Connectuon Data hd apfo
IData roLo Collec hê
Command Select Canmand
Inaet ommand Data colmh
Data Reade Updote CamCarrmo d Collecttn
Delect Command Dota Relahion
CollectLon

Exterded
Propenties

Datab ase
.NET Daka provider
acts as a bridge
Data proVid er class and data base
between an applicakon
sed to ekieve data rm
TE is to the database
Jotabase and send back
a<ker changes Ewo ipes of
Contains
. NET 1ameuomk
data providen
provider fox mic nosel t sQL
1. NET pota
SERVER data Sou ces

Daka Provider to OLEDB data


à. -NET
Sowces.

Dato pravider Consist e toun objec E


-NET
Cormpenen i.
ohjeck pnaVides Corneclivl
1. Connection
to a database

2. Command object allous to accets


database Cormmanda
PataReader - object provides data
8.
Streorn nom the database.
A. DataAdapln object puvides the
betwee n dataset & database
bridge
Connectuon obiect and coronnand cbjecks

Connectuon objec '


wsed to C1eake
These object ane
Connecfion to Lhe database fon meving
data bekueen the dotabue and Usen
applicatuon
The Conrnec tion Can be coeake d Using
oleDbConnechuon on SalConneckuon objecE
Methoda Connec Hion objech
Connecton
I. open () - Used o open a
clase c)- Used to close a Conneckton
a
that already open
3. dispose c)- sed o close a cônnection
Propenkies Conneckin object!:
1. Connechin skring’ Used o define
#he dakabase which is to be lonnecEed

Fxample
DIM Conn AS Solconnecton
Conn - Neuw Sal tonnecH on C)
Conn. Connech ionskring - dota Souote
sass,niEal cataloq-skd ;
Aud
liser id = Sa :
Cono .opent)
To the above Code , data source s
the name Ehe SQL SeVen inst an ce which
tfs ko be Connecked. nkial cakaleg s the
hame g the atabase usey iod is Ehe
Sel Sen Ven Login account and pwd is
the paSSUoMc
The user must close the Connecton
e
ayan using it is dare by either clos
dispose mekhod

Conn. closec ).
Cormmand objecks :
used to iead , add
These objecbs atetecoMcs in a databax
Updale and delete selec
Cornmanda hke
using database
dele ke etc
These openat on ate done by the
oljecks ole Db Conm an d or SlCormman d

Hethods Command object -


-1. ExecuteReaden () - Used to exe cuabe
Cormm an d and netnieye owS 1rom the
data base
2 Exeutebn QueyO - USe d ko exeut
a Command uithout ebrieving y
Propenties Cormand objeck
1 Connech on USed to make a Connecb D
the neguned dalabase.
with
a. Command Text used Lo Set the
Comman d to be exe uted

Fxample
DIH Conn As Sltonnecton
DIH Comm AS Sltommand
Conn = Neo Solconnech ton C
Conm = ew 89ltommand C)
Conn Connechtonstrinq = dabakcunce asdl;
inital Cabaog =shud ; usas id-Sa Pud-*
Conn.open C)
Com m.Conne cton lonn
Comm. Command Te xt " Select no
skud Table
The abe Code shoss how Eo to set a
Copmmand on to Select all ows uom
the table Stud Table in a sQl
Seven dotabase sted.
Data Readen'
used Mead
These obje ct
Pow uwise daka
data in
ony omat fnom
databases
SQL DakaReader o oleDbpat aReade
object is used depe nding On the
database
pataReader objech i
Methods o
Used to ret nieve ous
c) -
I Fxeute Readen accending
to the
rom khe database
Comnand
the rous Dne
vSe d to 1ead
Q Read
c)- esult a guey
nomthe to ow
by one alse i4 ho
ho moNe
JE 1ekuwns
iead
USe d to retniave
3. GetsEing () - Paskicalan u
Column Value ot
4 close ) Used to clase a OPenCHeate
JE is not possible ke
pata Readen .Jt
aReader Unti]l i is closed
anothen pat
Ex ample'
DIM Conn As Slennect ton
DIH Comm As Sal Coo mand
DIN d As SalDataReuder
Conn =New sqlconnectuon ()
Comm New Sollomman d
Conn. (onneckionSting = doka Sorce =asdJ,
Cataloq =Stud ; usenid - Sa s pud.
iriial
Conn open ()
Comm. onnect Lon= Conn
stud lal
Conm. Comand Text Select 1omn
1d - Comm ExecutReadet
Do chile 1d. ead ()
NSgbox dgedsving (o) Vbcm &
1d gelsrig0)
Loop
Hd. close C)
Conn. close C)
Data Adopken
This object is used to exc hange
data bek ween a database nd
dataset
DE 1e ods data dyom the dakabse
to Lhe dotaset and Ehen tunite
the chanqcd data back ko he dlababase
Data Adaphen Can be impleenbed
Using he olaDbDakaAdlapter objed or
SiDatandapl on chect dependig on the
ype database.
Nelheds Datafbaple chjeck

select Comman d inko Ehe dakaseh


Poropekies < pakapdaplorn objeck
LSelect Command - Used ton accesing
tous in a database

Used om insesLinq
a. Jnset lornmand -abase
ows in to dat
3. Update Comman d - Used for modifying
Pows in the database
H. pelekelomm and_ used ton deletinq
rom he database

Facample i
DIM Conn As Sltonnec on
DIM Comm As Slcomnand
DIN ada As SylDat a Adap
DiN ds As Pataset
Conn - New Saltonnech on c)
Cormrn - New sgl tomnand ()
ada a Neuw SalDaka hdopen t)
Conn. lonnechonstving =
înitiol cat ala =SEudj User id Sa)
Pwd n";

Conn. open C)
Comm lonnector Co
Comm. Comm and Tet - Table
ada e Select tovnand =lanm
ada 4il1 (ds, shudiable )
Conn. close ()
The above Progam is wsed to accey,
all xous nom the shud TaHe and
wmie nto he okase
Datasek
Dataset is a kempoiay stone o 1eCody
tctnieved rom dalabase Dt is
|Cache o MeCosds that incLude one O1 mo 1Q
Aable and the e la kionship among Ehem
Ahe
patasot must Contain atleast bne
DataTable object in it DataTablecolleehon
Each pataTable Contoins both a
ata Rouwtollec -thop and a patacolumn tollec ton
NewRow, pdd, Remove,pelete cn d
Aceptchunges ate Sonme Important me thod
in Patoset
To accesA data usinq pataset, the
st sep is to Ceate an instan ce
o Dataset by calling he pata sel
Con6 bructo n. Then the Cormeponding
Code is wnitten as belouw'
Fxomple
Dim Conn As sel tornecton
Dlm Comm AS
As lommand
Dim md ns atapdapten
Dim ds As Dabase L
Conn = NewSaltonnech ion C)
Comm New slcom mand t)
ada
ds New Datase c)
Conn. Conrecicns ving ' data Soun ce =aso
initial Ca Faloq =shud ; Usey id o Sa jpwd
Conn .open ()
Comm. Connec hop = Conn
Cornm . Com mandText seleet oro StedTabe
oda .Select torm mand = Comm
ada. fiD (ds sud Table e
Conn close (2.
DakaReaden Vs Dataset el
be acc essedl Us ing eihen
Pata can
DataReacden by Data sek
Set;l
using DataReaden, DSern Can qet
But
than palasel
betken'perfoinance the
giver below shows,
The table
ootaReaden & Daaset
Compenisorn d i
DataReader Dataset

Less amaunt o memo Lasge amount < J


is Hesuned memoy is equned

Less pro cesSing


time Eime.

oks on Connec ted woks or dalomecte


mode moda

Undorstancding Dakaset
Dataset is a kemponny stong
1e cods ccesbed nom the databose
î is relatonaL data truct ue that
Can be 4eead 1rom n. wite to the
data ownce Vsing XML.
Dakqset object Holel .
The dataset ConE ain S Datalabe colecto
and Data Re lo uÛ collechop that repreen
a Collecton e data tetgieve d nom
the database.
we Cor Use dat se Combined wiEh
Pata Adaper, The Dat aset can wosk
with khe data toom Hhat was
Metive d, om the databae
dbeady dis connected mode
That meons iE Can wok with the
data without Ehe knouledge data
SouMce

Dakase A

pakaTable Collecton
PatalabHe
DataRow Colle chon
|Pata Column collecton

Consteint collecho

Pata Relot ional Connecton

to t
CarrContaen
the the opX
The pataset
the daka we Hequested. Dotaset
ContoinS One mote at a
table ot
kime. Using DataRelation we Car

elations bet ween the tables in


the Dataset
Datasot

Dakafdaphern

Command

Connecton

Data Sout Ceole i

the Fil C) method o the


By vsing data.Can be ans<ered
DatafdlapAon ,
Dataset. The Data is saved
to the oaded ioto
and then
as XHL ile
the memony easiy.
There ae thee fmpotant objecti
in atase t -
1: Data able object.
a. DakaRow objec
3. PataTableCollechon object'
Datalable
d databas must Contain alest
One Datala ble object. A DataTable
pbject n wst Contain ateast bne
Lable
Set Codumns în a Lable
Emeated as Data Columntollectuon and
the Set ows aste t teak ed
DataRow lritue Collection
Methos -
a) New Row() Used Eo add a new Ste

b)
L) Accept changes used to Contirn the
te Co
addito hew
Q.DataRows -
Al the ne cots a data tablos
available in th object
Hethod '
pddc used o add a
)
the pata Rowlollect uon
b) Remove () Used to delete a

rom Ahe DotaRowcol lecton


3.pataTableconn ecton
is wsed to pnovide
This obiect a
all Lhe DataTable objects
Data Set like pataRow Collectoi
Columncollectuon and Constraint
Data
Cdlect on

You might also like