3.0 Ado - Net1
3.0 Ado - Net1
3.0 Ado - Net1
ADO.NET
Outline
Relational Database
A collection of data items organized as a set
of formally described tables from which data
can be accessed easily
Database Terminology
Field - contains an item of data
Database Terminology
Record - composed of a group of related fields.
- A record contains a collection of attributes related
to an entity such as a person or product
Database Terminology
Database file - defined as a collection of related records.
- A database file is sometimes called a table.
Database Terminology
DATABASE - composed of related files that are
consolidated, organized and stored
together.
Database management system - software package that
enables users to edit, link, and update files as needs dictate
Database Terminology
Key - unique identifier , required by each record, in order
to track and analyze data effectively
ADO.NET
(ActiveX Data Objects ADO)
ADO.NET - technique of developing computer databases
using the Microsoft .NET Framework.
It is meant to serve stand-alone computers, client/server
scenarios at the enterprise level, and web applications.
Its full support for security, XML, file processing, and ease
of deployment makes it a very viable solution to creating
powerful applications.
This is the FunctionX support site of ADO.NET, providing
lessons and topics on how to use ADO.NET to develop
various types of data and list-based applications.
Function of ADO.NET
ADO.NET makes it possible to establish a connection with
a data source, send queries and update statements to the
data source (SQL Server & Ms Access), using XML for
passing the data, and process the results.
ADO.NET Architecture
Diagram
The following figure shows a scenario in
which the application and the ADO.NET
data provider are both built with managed
code. The application can connect to a
database using either a DataSet and a
DataAdapter or using a DataReader.
ADO.NET Architecture
Diagram
ADO.NET
(Data and XML)
ADO.NET
ADO.NET is the preferred data access
method in the .NET Framework
Better support for disconnected data
access
Specialized namespaces
System.Data.SQL Tuned for SQL Server
System.Data.ADO OLEDB
Portable
Native XML Support
ADO.NET
ADO.NET object model:
a. DataAdapter
b. Command
c. DataReader
d. DataSet
ADO.NET
ADO.NET is comprised of many classes, but five take
center stage:
Connection - Represents a connection to a data source.
Command - Represents a query or a command that is to
be executed by a data source.
DataSet - Represents data. The DataSet can be filled
either from a data source (using a DataAdapter object)
or dynamically.
DataAdapter - Used for filling a DataSet from a data
source.
DataReader - Used for fast, efficient, forward-only
reading of a data source.
ADO.NET
ADOConnection
Similar to Connection object in ADO
ADOCommand
Similar to Command object in ADO
ADODataSetCommand
Somewhat like Recordsets for ADO.NET (DataSet)
Designed for stateless operations
ADODataReader
For streaming methods, similar to Stream
18
19
20
Databases
Microsoft SQL Server
Microsoft Access
Oracle
10/30/16
C
o
n
n
e
c
ti
o
n
Data providers
Data Adapter-Dataset
Command Data Reader
Data consumers
Windows Form
Web Form
Other
21
Binding
Source
Table
Adapter
Dataset
Windows
Form
BindingSource
object
Specific file
or database
10/30/16
Data display on
the form
in bound
controls
Actual data.
Can contain
multiple tables
and relationships
22
10/30/16
23
10/30/16
24
Database Connectivity
Following are important to get connected
to the database and perform operations
Connection Object
Command Object
Operation on the Command Object
Using Dataset and Data adapter
Using Data Reader
Connection Object
Dim con as New
OdbcConnection(connectionstring)
Command Object
Dim cmd as New
OdbcCommand(strCmd,con)
strCmd is the
select/insert/update/delete statement
or exec <<storedProc>> command
Con is the connection object created in
the first step
Properties cmd.CommandType
This can be either Text or StoredProcedure
Command Methods
Cmd.ExecuteReader() Returns one or
more table row(s) for select
statement
Cmd.ExecuteScalar() Returns a single
value for select statement with
aggregate function
Cmd.ExecuteNonQuery() Used for
executing stored procedure or
insert/update/delete statements
Data Set
Dim ds as New DataSet()
ds holds the result of select statement
Data adapter is used to fill the data set
Data Adapter
Data adapter fills in the data set with
the result of the select query
Dim da as New OdbcDataAdapter(cmd)
Cmd is the command object created
da.Fill(ds) fills the dataset
The data set can be set as a data
source for various controls in the web
form or windows form
ADO
ADO.NET
Primary Aim
Client/server coupled
Disconnected collection of
data from data server
Form of data in
memory
Disconnected
access
Uses DATASETCOMMAND
object with OLEDB
Disconnected
access across
multi-tiers
ADO
ADO.NET
XML
capabilities
XML aware
Firewalls
Code
Exercise
Create a Windows application that
displays data from the Book table of
the Book.mdb database. You will
display the fields from the table in a
DataGridView control on a Windows
Form.
10/30/16
35
Resources
http://en.wikipedia.org/wiki/Comparison_of_ADO_and_ADO
.NET
http://msdn.microsoft.com/en-us/library/dw70f090(v=vs.80).aspx
ADO.Net Sample Application. Retrieved 03 March 13
Mahesh Chand (2009 ). Simple ADO.NET program with Visual Studio
.NET IDE
http://www.c-sharpcorner.com/uploadfile/mahesh/simple-ado-netprogram-with-visual-studio-net-ide/ Retrieved on 3 March 13
http://oreilly.com/catalog/progvbdotnet/chapter/ch08.html Retrieved
on 3 March 13
Extra Activity
Refer to Extra Lab