session x(ado.net)

19
Overview of ADO.NET Architecture of ADO.NET .NET Data Providers Data Providers Components

Upload: shrijan-tiwari

Post on 28-Jul-2015

58 views

Category:

Software


0 download

TRANSCRIPT

Overview of ADO.NET

Architecture of ADO.NET

.NET Data Providers

Data Providers Components

ADO.NET is a large set of .NET classes that enable us to retrieve and manipulate data, and update data.

As an integral part of the .NET framework, it shares many of its features:

sources, in very many different ways.

features such as multi-language support, garbage collection, just-in-time compilation, object-oriented design,

and dynamic caching, and is far more than an upgrade of previous versions of ADO.

The ADO.NET object model consists of two fundamental components: the Dataset, which is disconnected from the data source and doesn't need to know where the data it holds came from; and the .NET

data provider. The .NET data providers allow us to connect to the data source, and to execute SQL.

At the time of writing, there are three .NET data providers available: for SQL Server, for OLE DB data sources.

for ODBC-compliant data sources. Each provider exists in a namespace within the System. Data namespace, and

consists of a number of classes.

Each .NET data provider consists of four main components:

Connection – used to connect to the data source

Command– used to execute a command against the data source and retrieve a Data Reader.

Dataset, or to execute an INSERT, UPDATE, or DELETE command against the data source

Data Reader– a forward-only, read-only connected result set.

Data Adapter – used to populate a Dataset with data from the data source, and to update the data source

The connection classes are very similar to the ADO Connection object, and like that, they are used to

represent a connection to a specific data source. The connection classes store the information that ADO.NET

needs to connect to a data source in the form of a familiar connection string (just as in ADO).

The command classes expose the IDbCommand interface and are similar to the ADO Command object – they

are used to execute SQL statements or stored procedures in the data source. Also, like the ADO Command

object, the command classes have a Command Text property, which contains the text of the command to be

executed against the data source, and a Command Type property, which indicates whether the command is a

SQL statement, the name of a stored procedure, or the name of a table.

The DataReader is ADO.NET's answer to the connected recordset in ADO. However, the DataReader is

forward-only and read-only – we can't navigate through it at random, and we can't use it to update the data source. It

therefore allows extremely fast access to data that we just want to iterate through once, and it is recommended to use

the Data Reader (rather than the DataSet) wherever possible.

The other major component of ADO.NET is the DataSet; this corresponds very roughly to the ADO

recordset. It differs, however, in two important respects. The first of these is that the DataSet is always

exactly the same way to manipulate data from a traditional data source or from an XML document. In order to

connect a DataSet to a data source, we need to use the DataAdapter as an intermediary between the

DataSet and the .NET data provider: