2. What is ADO.NET
• ADO.NET (Active Data Objects) is the data access
component of the .NET Framework
• Used to develop data bound Windows Forms and Web Forms
• Like other components of the .NET Framework,
ADO.NET consists of a set of classes that
interact to provide the required functionality
• VS 2008 (and greater) and .NET 2.0 (and greater) make
development much easier
• ADO.NET classes are divided to two primary components
• Data Providers handle communication with the data source
• Data Sets represent the actual data from the data source
3. ADO.NET Object Model
• The primary objects in the ADO.NET object model
• The true reality of the class library is
considerably more complicated
4. Data Providers
• Data Provider components are specific to a data
source
• A generic provider that can communicate
with any OLE DB data source (Access etc)
• An SQL Server provider, optimized
for SQL Server 7, 2000 & 2005
• An ODBC provider that can communicate
with an ODBC data source (MySQL etc)
• An Oracle provider, optimized for access to Oracle
• Data Providers contain the same objects
• SqlConnection, OleDbConnection, OracleConnection etc
5. SqlConnection
The SqlConnection class is used to establish a
connection to a SQL Server database. The SqlConnection
class is used for opening connections, setting or
retrieving properties of a connection, or handling
connection-related events.
Connection objects represent the physical connections
to data sources
• Their properties determine the data provider,
the data source, the database to connect to
and the string to be used during connection
– Their methods are fairly simple. You can open
and close the connection, change the database
and manage transactions
6. SqlCommand
The SqlCommand class is used to execute SQL statements
or stored procedures against a SQL Server database. The
SqlCommand class can execute statements or stored
procedures that do not return values, or that return
single values, XML, or datareaders.
• Command objects can be executed against a connection
They are also used by DataAdapter objects to handle the
communication requirements of DataSet objects.
7. SqlDataReader
The SqlDataReader class provides forward-only, read-
only only access to a set of rows returned from a SQL
Server database. Datareader provide high-performance
access to read-only data and is the
best choice for accessing data to be displayed in
ASP.NET.
• DataReader objects can not be created directly
in code as they are constructed by calling the
ExecuteReader method of a Command object
8. SqlDataAdapter
The SqlDataAdapter class is used as a bridge between the
DataSet class and SQL Server. You can use the
SqlDataAdapter class to create a dataset from a given
SQL statement or stored procedure represented by a
SqlCommand instance, to update the back-end SQL Server
database based on the contents of a dataset, or to
insert rows into or delete rows from a SQL Server
database.
• It provides an automated bridge between
a Connection object and a DataSet object
• A DataAdapter object contains four Command
objects, one each, for SELECT, UPDATE,
INSERT and DELETE based SQL statements
11. Data Sets
• The DataSet object is a memory resident copy of data
• The DataSet can be considered a somewhat simplified
relational database as it models tables and any
relationships between them
• The DataSet is always disconnected from the data source
• The DataSet is composed of two primary objects
• The DataTableCollection, accessed
through the Tables property
• The DataRelationCollection, accessed
through the Relations property