.NET-2nd Unit
.NET-2nd Unit
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
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
DataSet
Dataset is a Fempo SkoMegf data
twy Vinkual
like a
1e Comcls 7t wDHks
a
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
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
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
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
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
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
Dakafdaphern
Command
Connecton
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