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

Working with Connection Oriented Model

Sekhar Srinivasan
@sekharonline4u I
sekhartheguru.net
Working with Connection Oriented Model

CRUD Consuming Using


Operations Stored SQLBulkCopy
Procedures

Storing Retrieving Connection


image in DB Image from Pooling
Database
Steps to Work with ADO.NET Connection Oriented
Model
Define a Connection Object - - - .

Define a Command Object


Connection + - - - - - - - - - ' Text
CommandType - - - - - - - - - - + - - -+ StoredProcedure
CommandText = uSQL . : TableDi
Statement/Table/SP"
[Parameters] rect

Open the Connection

Select Statement Any Valid Statement other than Select

t ExecuteReader()
ExecuteScalar( L ExecuteNonQuery()

[Close t )he
Connection]
Performing CRUD Operations
Comp on yNar R ev en ue

-;-- ' 113s!M:i


1
48500.0000
IORACLE 35000.0000


,GOOGLE
42500.0000
Using Connection Oriented Model
FILE
VIEW
EDIT PROJECT BUILD DEBUG TEAM TOOLS TEST ARCHITECTURE ANALYZE WINDOW HELP Ful l
Screen
0
10

'!: WorlcingWithConnection0rientedModel.adonet.by_examples
Form I .cs ;; "" X _04_03.after.For m1 - Ii> btnUpdate_Clic.k(object sender. EventArgs
el
G private void btnSearch_Click (object sender, EventArgs
e)

Company R e ve nu e s - 2 01 5

Compony Name ; !MICROSOFT S ear c h

Re ven u e : 4 8 5 0 0 . 00 0 0

B
Add
l U p dat e D el e t e Prev iew

CompanyNa r Revenue
48500.0000 - Sefies1

ORACLE 35000.0000
GOOGLE 42500.0000

ORAO .E
MICROSOFT GOOGL
E
What We Covered

l!

--
' I

Performing CRUD Operations


Using Connection Oriented Model

--
-
Consuming Stored Procedures

Videos
-
GetVideos
Videold
J
VideoTitle

GetVideo
VideoURL
-
-
FILE EDIT VIEW PROJECT BUILD TEAM
DEBUG
Program.cs ff! C.on.sumingStoredProcedures.cs ;:i X
a
WorkingWithConnectionO
Available
Albums
Cartoon
WildUf
e
I
El priv
a I
{
A
}

El priv
a
{
iD
{

}
}
}
(I) 14 CI = = ' i< - - Oose
Application
}
- - -
pluralsig!'Jto
Read Ln Col Ch 1
SQLBulkCopy
Moves data from one table to another on a single server or different
servers.

Offers a significant performance advantage


Used to write data only to SQL Server
tables
Any datasource can be used
SQLBulkCop
Source Product

ProductId
y Target Product

Productld

ProductName ProductName
-
QuatityPerUnit QuatityPerUnit

UnitPrice UnitPrice

l ....
l - ....

.....
- -
" " " " "ii
"""""...
1 """""......
11 I"' 10bcMs I ; 20blil UUlO 1
, 2,
" """" I"' 10ticor. x 2Dblgt
2
l
2
""
-s,...
l'
.
2' . 12 o t bcdl!ll
19.0
0
2
3 iil ...""
-s,...
1l00
24 -12oz 19.00

3 "'"""'"' 12. 550ml boldes 1noo boal9I inoo

' Bo7ti.v 2200 "'"""'"'


'.anon.Wnbo,.
Oicl 12.S50 ml

-- --
$ $ C h o i h U n \ W.. . . . . . 4.l&Olja
$ $ s.-.. bclldM
21.35 GwdM" BcrJ-C.r
"""
6 6 Gwwba'a 3 6 - 6 6 SpeMd '8Goijh 2200

...
Spread
lhd e 8cb. .'9l"e lll!ed 12 80tl!n 2500
1 1 1 1 ,lh de Bcb\ lll!ed - 36bcooo 21.3$
"""' 12. 1b pkgil. 3000 fblh : 128oi51n 2500
a
... a
...
8

' '
dii:OrbenySll.ice
' '
12 12oijl n <noo 121b..... 30.00
a10
-""""s..a
19500. . . . . .. 97.00 10 12 12ozj.n 40.00
10 0 . - 12- 2001111. . 31.00 10 0 . -C > b w. 18500gpkp 97.00

. .
11 21.00 11 12200m1Jn 31.00
11 11 21.00
Storing Image Within the Database

Define a FileStream object using the image file as the source

Define a BinaryReader object to read the data present within


the FileStream as a binary data

Define a byte array variable

Read the data from the BinaryReader object

Assign it t o the byte array variable


What We Covered

,.....

_..,

-- Storing image within the Database


O. 23-09 ;zo1s Mobile Day
Tim 1 1 :<>OAM Sekhar Srinivasan

[ ---4-
Retrieving Image from the Database
To Do
Interact with the database

Fetch the data to the datareader


Define FileStream object

Define BinaryWriter object

Read the data from DataReader as


ByteArray

Write data to BinaryWriter object

Flush t o save the content as an image file

Assign image file t o the picturebox


EIL
E
DIT
lilEW
eROJECT
UILD
QEBU
G
TEA
M
IOOLS TE2
T
AR!:;HITECTUR
E
ANALVZE
WINDOW
J::!
ELP
Fyll Screen
CJ ,..10 IQuick Launch tJ Signin B
RetrevinglmageFrom TheDatabase.cs X (Ctrl+Q)
O
WorkingWithConnectionOriented Mod el.adonet_by_exam
ples_04_03.after.RetrevinglmageFromTheDatabase
SqlOataReader dr = cmd .ExecuteReader
( ); *
aD if (dr.Read ())RetrevinglmageFromDatabas -
CJ ...
e
Event I D : ,_ GetI
I

Event Trtle : laoud Compt.ting 0ay

eate, FileAccess
.Write);
Date : lwednesday. September 23. 201 5

Cover Photo :

C lo u d C o m p u t i n g I
by
S e k h a r Sriniv asa n

Oose

Read Ln Col 1 Ch 1
Understanding Connection Pooling
Application Connection

Ado.net Socket
'

1
Authenticate

1
1
e
Understanding Connection Pooling
.

Pooler

Connection Object
Sent to Pool
Understanding Connection Pooling
.

Pooler

Connection Object
Sent to Pool
Understanding Connection Pooling
.

Pooler

Connection Object
Sent to Pool
Understanding Connection Pooling

Soft .,. Hardconnects ,...


Conney
_ .
Soft . . . - - - {X} - - - - - - +
Disconnects Harddisconnects
Summar
y ADO.NET Connection Oriented Model

E l - CRUD Operations
El
D How to interact with the stored

El procedures? Storing the images within the


D -=- database &

==-- retriving them

What is connection pooling in ADO.NET?

plural ighto

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