Sei sulla pagina 1di 4

ADO and ADO.

NET are different in several ways:


ADO works with connected data. This means that when you access data, such as viewing and
updating data, it is real-time, with a connection being used all the time. This is barring, of course,
you programming special routines to pull all your data into temporary tables.
ADO.NET uses data in a disconnected fashion. When you access data, ADO.NET makes a copy
of the data using XML. ADO.NET only holds the connection open long enough to either pull down
the data or to make any requested updates. This makes ADO.NET efficient to use for Web
applications. It's also decent for desktop applications.
ADO has one main object that is used to reference data, called the Recordset object. This object
basically gives you a single table view of your data, although you can join tables to create a new
set of records. With ADO.NET, you have various objects that allow you to access data in various
ways. The DataSet object will actually allow you to store the relational model of your database.
This allows you to pull up customers and their orders, accessing/updating the data in each related
table individually.
ADO allows you to create client-side cursors only, whereas ADO.NET gives you the choice of
either using client-side or server-side cursors. In ADO.NET, classes actually handle the work of
cursors. This allows the developer to decide which is best. For Internet development, this is
crucial in creating efficient applications.
Whereas ADO allows you to persist records in XML format, ADO.NET allows you to manipulate
your data using XML as the primary means. This is nice when you are working with other
business applications and also helps when you are working with firewalls because data is passed
as HTML and XML.

In-memory Representations of Data


In ADO, the in-memory representation of data is the recordset. In ADO.NET, it is the
dataset. There are important differences between them.

Number of Tables
A recordset looks like a single table. If a recordset is to contain data from multiple
database tables, it must use a JOIN query, which assembles the data from the various
database tables into a single result table.
In contrast, a dataset is a collection of one or more tables. The tables within a dataset
are called data tables; specifically, they are DataTable objects. If a dataset contains data
from multiple database tables, it will typically contain multiple DataTable objects. That
is, each DataTable object typically corresponds to a single database table or view. In
this way, a dataset can mimic the structure of the underlying database.
A dataset usually also contains relationships. A relationship within a dataset is analogous
to a foreign-key relationship in a database that is, it associates rows of the tables with
each other. For example, if a dataset contains a table about investors and another table
about each investor's stock purchases, it could also contain a relationship connecting
each row of the investor table with the corresponding rows of the purchase table.

Because the dataset can hold multiple, separate tables and maintain information about
relationships between them, it can hold much richer data structures than a recordset,
including self-relating tables and tables with many-to-many relationships.

Data Navigation and Cursors


In ADO you scan sequentially through the rows of the recordset using the ADO
MoveNext method. In ADO.NET, rows are represented as collections, so you can loop
through a table as you would through any collection, or access particular rows via ordinal
or primary key index. DataRelation objects maintain information about master and
detail records and provide a method that allows you to get records related to the one you
are working with. For example, starting from the row of the Investor table for "Nate
Sun," you can navigate to the set of rows of the Purchase table describing his
purchases.
A cursor is a database element that controls record navigation, the ability to update data,
and the visibility of changes made to the database by other users. ADO.NET does not
have an inherent cursor object, but instead includes data classes that provide the
functionality of a traditional cursor. For example, the functionality of a forward-only, readonly cursor is available in the ADO.NET DataReader object. For more information about
cursor functionality, see Data Access Technologies.

Minimized Open Connections


In ADO.NET you open connections only long enough to perform a database operation,
such as a Select or Update. You can read rows into a dataset and then work with them
without staying connected to the data source. In ADO the recordset can provide
disconnected access, but ADO is designed primarily for connected access.
There is one significant difference between disconnected processing in ADO and ADO.NET.
In ADO you communicate with the database by making calls to an OLE DB provider. In
ADO.NET you communicate with the database through a data adapter (an
OleDbDataAdapter, SqlDataAdapter, OdbcDataAdapter, or OracleDataAdapter object),
which makes calls to an OLE DB provider or the APIs provided by the underlying data
source. The important difference is that in ADO.NET the data adapter allows you to
control how the changes to the dataset are transmitted to the database by optimizing
for performance, performing data validation checks, or adding any other extra
processing.
Note Data adapters, data connections, data commands, and data readers are the
components that make up a .NET Framework data provider. Microsoft and third-party
providers can make available other .NET Framework data providers that can be integrated
into Visual Studio. For information on the different .NET Data providers, see .NET Data
Providers.

Sharing Data Between Applications


Transmitting an ADO.NET dataset between applications is much easier than transmitting
an ADO disconnected recordset. To transmit an ADO disconnected recordset from one
component to another, you use COM marshalling. To transmit data in ADO.NET, you use a
dataset, which can transmit an XML stream.

The transmission of XML files offers the following advantages over COM marshalling:

Richer data types


COM marshalling provides a limited set of data types those defined by the COM
standard. Because the transmission of datasets in ADO.NET is based on an XML format,
there is no restriction on data types. Thus, the components sharing the dataset can use
whatever rich set of data types they would ordinarily use.

Performance
Transmitting a large ADO recordset or a large ADO.NET dataset can consume network
resources; as the amount of data grows, the stress placed on the network also rises.
Both ADO and ADO.NET let you minimize which data is transmitted. But ADO.NET offers
another performance advantage, in that ADO.NET does not require data-type
conversions. ADO, which requires COM marshalling to transmit records sets among
components, does require that ADO data types be converted to COM data types.

Penetrating Firewalls
A firewall can interfere with two components trying to transmit disconnected ADO
recordsets. Remember, firewalls are typically configured to allow HTML text to pass, but
to prevent system-level requests (such as COM marshalling) from passing.
Because components exchange ADO.NET datasets using XML, firewalls can allow datasets
to pass.

ADO AND ADO.NET


ADO is ActiveX Data Object that allows you to use data from databases without
knowing the implementation of such a database. To access the data programmer
even don't have to know SQL although there is a possibility of using SQL commands
through ADO as well. One of the main objects in ADO is a Recordset, it will be
described in details later in this tutorial. The general idea of using ADO is the
following: firstly you have to create and open a connection object that allows you to
connect to the database. Then you create a Recordset and retrieve data from the
database to it. Afterwards you have the possibility to save potential changes to the
database.
ADO.NET is ActiveX Data Object for .NET and it's a successor to ADO.NET
although it was changed completely. Its functionalities are similar to the ones from
ADO. It allows you to connect to data sources and perform some operations on
them. The main object in ADO.NET is Dataset, it's a bit similar to Recordset but it
provides more possibilities for developers. ADO.NET makes possible disconnected
access to data by taking advantage of XML files.
ADO.NET provides also frameworks that make using databases even simpler. One
of them is ADO.NET Entity Framework for object-relational mapping. It presents data
from databases as objects and thus makes it much easier to use it by rising level of
abstraction. Another framework that is very useful is LINQ (Language Integrated
Query), which allow you to query data in a unified and clear way. The main

advantage of it is that there exist various providers with which you can query not only
databases but also other data sources such as XML, objects or DataSets. If you
want to learn more about LINQ check out our previous tutorials.
Here is a list of main differences between ADO and ADO.NET :
ADO.NET uses disconnected models based on messages whereas ADO is
rather connection oriented
ADO.NET supports XML in an easy and clear way, moreover it uses XML for
passing data. On the other hand standard ADO uses binary representation
for passing data.
ADO is based on COM (Component Object Model) and ADO.NET uses CLR
(Common Language Runtime)
Recordset in ADO and DataSet in ADO.NET

DATASET AND RECORDSET


Recordset represents data in memory, usually it's a table or result of a query such as
joining two tables or using where clause. At one time there can be only one current
record in Recordset, if you want to perform operations on other record you have to
use move method. On the other hand DataSet can contain one or more tables from
database, these tables are stored in object called DataTable. It is also very easy to
retrieve data from it, you can use simple foreach loop to do so. With DataSet you can
also maintain relationships between data tables such as for instance foreign key.
Generally DataSet can include more rich and complex data and organize it in a clear
manner.
As I mentioned before ADO Recordset requires constant connection to database to
perform some operations on it while ADO.NET DataSet allows you to make changes
and submit all of them to the database later. ADO.NET uses also data adapter which
communicates with OLE DB provider while in ADO you communicate with it directly.
Data adapters are significant advantage because it's very easy to set up and
manage this connection (you can for instance optimize data transfer for
performance)
Also performance of DataSets is better because of its architecture, it's faster and
more portable than Recordset.
DataSet stores data in XML so it's easier to transfer it to other applications and they
are more firewall-prove than Recordsets that are transferred using COM marshalling.
Summing up DataSet is better and more robust tool to manage data from databases
and it provides more functionalities. Now I'll show you how you can use DataSet in
your applications:

Potrebbero piacerti anche