ADO.NET Overview C# Help

ADO.NET is more than just a thin veneer over some existing API. The similarity to ADO is fairly minimal- the classes and methods of accessing data are completely different. ADO (ActiveX Data Objects) is a library of COM components that has had many incarnations over the past few years. Currently at version 2.8,ADO consists primarily of the Connection, Command, Recordset, and Field objects. Using ADO, a connection is opened to the database, some data is selected into a record set consisting of fields, that data is then manipulated and updated on the server, and the connection is closed. ADO also introduced a so-called disconnected record set, which is used when keeping the connection open for long periods of time is not desirable.
There were several problems that ADO did not address satisfactorily, most notably the unwieldiness (in physical size) of a disconnected record set. This support was more necessary than ever with the evolution of WelKentric computing, so a fresh approach was required. Upgrading to ADO.NET from ADO shouldn’t be too difficult because there are some similarities between the two. What’s more, if you’ are using SQLServer, there is a fantastic new set of managed classes that are tuned to squeeze maximum performance out of the database. This alone should be reason enough to migrate to ADO.NET.
ADO.NET ships with four database client namespaces: one for SQLServer, another for Oracle, the third for ODBC data sources, and the fourth for any database exposed through OLE DB, If your database of choice is not SQLServer or Oracle, use the OLE DB route unless you have no other choice than to use ODBC.


All of the examples in this chapter access data in one way or another. The following namespaces expose the classes and interfaces used in .NET data access.

The main classes in ADO.NET are listed in the following subsections.

Shared Classes

ADO.NETcontains a number of classes that are used regardless or whether you are using the SQLServer classes or the OLEDBclasses. TIle fo owing classes are contained in the Sys tern. Data namespace.

The following classes are found in the System Data Common namespace:

Class                                        Description

DataColumnMapping: Maps the name of a column from the database with the name of a column within a DataTable.

DataTableMapping: Maps a table name from the database to a DataTable within

Database-Specific Classes

In addition to the shared classes introduced in the previous section, ADO.NET contains a number of database-specific classes, These classes implement a set of standard interfaces defined within the System, Data namespace, allowing the classes to be used in a generic manner if necessary, For example, both the SqlConnection and OleDbConnection classes derive from the DbConnection class, which implements the IDbConnection interface.

As you can see from the previous list, there are four classes for each type of object – one for each of providers that are part of .NET version 1.1. In the rest of this chapter, unless otherwise stated, the prefix <provider> is used to indicate that the particular class used is dependent on the database provider use. With version 2.0 of .NET,the designers have updated the class hierarchy for these classes Significantly, In 1.1,all that was common between the various connection classes was the implementation of the IConnection interface, This has changed in .NET2.0 because now both share a common base class, Similarly the other classes such as Commands,DataAdapters, DataReaders, and SO on also share common base classes.

The most important feature of the ADO.NET classes is that they are designed to work in a disconnected manner, which is important in today’s highly Web-centric world, It is now common practice to architect a service (such as an online bookshop) to connect to a server, retrieve some data, and then work on that Data on the client before reconnecting and passing the data back for processing. The disconnected nature of ADO.NET enables this type of behavior.

ADO 2.1 introduced the disconnected record set, which would permit data to be retrieved from a database, passed to the client for processing, and then reattached to the server, This used to be cumbersome to use because disconnected behavior was not part of the original design, The ADO.NET classes are different- in all but one case (the <provider>DataReader) they are designed for use offline from the database.

ThL classes and interfaces used for data access in the .NET Framework are introduced in the course, The focus is mainly on the SQL classes used when connecting to the database because the Framework SDK samples install an MSDE database (SQL Server), In most cases, the OLE DB, Oracle, and ODBC classes mimic the SQL code exactly.

Posted on October 30, 2015 in Data Access

Share the Story

Back to Top
Share This