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

ADO.net_Object_model

Uploaded by

chhavisagar1234
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views

ADO.net_Object_model

Uploaded by

chhavisagar1234
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

ADO.

NET Object Model:


 ADO.NET provides an object-oriented API to a relational view of our database,
encapsulating many of the database properties and relationships within
ADO.NET objects. More importantly, the ADO.NET objects encapsulate and hide
the details of database access; your objects can interact with ADO.NET objects
without knowing or worrying about the details of how the data is moved to and
from the database.

 The ADO.NET object model provides an API for accessing database systems
programmatically.
 All ADO.NET related functionality appears under the System.Data
namespace.
 Data Access in ADO.NET relies on two components :

1. .NET Data Providers(Connection oriented).


2. DataSet(Connectionless)

A
DO.NET Object Model
NET Data Providers:

 A .NET Data Provider is responsible for providing and maintaining the


connection to the database.
 Following are the various .NET Data Providers:

1. .NET Framework Data Provider for SQL Server.


2. .NET Framework Data Provider for Oracle.
3. .NET Framework Data Provider for OLE DB.
4. .NET Framework Data Provider for ODBC.
5. The .NET Framework Data Provider for SQL Server uses its own protocol to
communicate with SQL server. The classes for this provider are located in
System.Data.SqlClient namespace.
6. Each Data Provider provides the following core objects:

A. Connection

B. Command

C. Data Reader

D. Data Adapter

A. Connection:

o This is the object that allows you to establish a connection with the
data source.
o Depending on the actual .NET Data Provider involved, connection
objects automatically pool physical databases connections for you.
o Examples of connection objects are OleDbConnection, SqlConnection,
OracleConnection and so on.

B. Command:

o This object represents an executable command on the underlying data


source. The command may or may not return any results. These
commands can be used to manipulate existing data.
o In addition, the commands can be used to manipulate underlying table
structures. A program can use Command objects to manipulate a data
source through a Connection. The program must open the connection
to the data source before executing one or more SqlCommands and
close the connection once no further access to the data source is
required.
o Examples of command objects are SqlCommand, OracleCommand
and so on. A Command needs to be able to accept parameters. The
Parameter object of ADO.NET allows commands to be more flexible
and accept input values and act accordingly.

C. Data Reader:

o This object is designed to help you retrieve and examine the rows
returned by the query as quickly as possible.
o DataReader object examines the results of a query one row at a time.
When you move forward to the next row, the contents of the previous
row are discarded.
o The DataReader doesn’t support updating. The data returned by the
DataReader is read-only. Because the DataReader object supports
such a minimal set of features, it is extremely fast and lightweight.
o The disadvantage of using a DataReader object is that it requires an
open database connection and increases network activity.

D. DataAdapter:

o This object acts a gateway between the disconnected and connected


flavours of ADO.NET. The architecture of ADO.NET, in which
connection must be opened to access the data retrieved from the
database is called as connected architecture whereas as in a
disconnected architecture data retrieved from database can be
accessed by holding it in a memory with the help of DataSet object
even when the connection is closed.
o Examples of DataAdapters are SqlDataAdapter, OracleDataAdapter
and so on. It has commands like Select, Insert, Update and Delete .
o Select command is used to retrieve data from the database and insert,
update and delete commands are used to send changes to the data in
dataset to database.

DataSet :

 It is an in-memory cache of data retrieved from the data source. Data is


organized into multiple tables using DataTable objects, tables can be related
using DataRelation objects and data integrity can be enforced using the
constraint objects like UnqueConstraint and ForeignKeyConstraint.
 DataSet are also fully XML-featured. They contain methods such as GetXML
and WriteXML that respectively produce and comsume XML data easily.
 The DataSet object provides a consistent programming model that works with
all the current models of data storage: flat, relational and hierarchial.
 Another feature of DataSet is that it tracks changes that are made to the data
it holds before updating the source data.

 The DataSet objects

1. DataTable : A DataSet object is made up of a collection of tables,


relationships, and constraints. In ADO.NET, DataTable objects are used to
represent the tables in a DataSet object.
2. DataColumn : Each DataTable object has a Columns collection, which is a
container for DataColumn objects. A DataColumn object corresponds to a
column in a table.
3. DataRow : To access the actual values stored in a DataTable object, use the
object’s Rows collection, which contains a series of DataRow objects.
4. DataView : Once we have retrieved the results of a query into a DataTable
object, we can use a DataView object to view the data in different ways. In
order to sort the content of the DataTable object based on a column, simply
set the DataView object’s Sort property to the name of that column. Similarly
the Filter property of the DataView can be used so that only the rows that
match certain criteria are visible.
5. DataRelation : A DataSet, like a database, might contain various interrelated
tables. A DataRelation object lets you specify relations between various tables
that allow you to both validate data across tables and browse parent and child
rows in various Data Tables.

You might also like