15.02.2015 Views

C# 4 and .NET 4

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

aDo.neT overview ❘ 819<br />

The following table lists the classes found in the System.Data.Common namespace.<br />

Class<br />

DataColumnMapping<br />

DataTableMapping<br />

desCriPTion<br />

Maps the name of a column from the database to the name of a column<br />

within a DataTable.<br />

Maps a table name from the database to a DataTable within a<br />

DataSet.<br />

database-specific Classes<br />

In addition to the shared classes introduced in the previous section, ADO.<strong>NET</strong> contains a number of<br />

database-specific classes. These classes implement a set of st<strong>and</strong>ard interfaces defined within the System<br />

.Data namespace, allowing the classes to be used in a generic manner if necessary. For example, both the<br />

SqlConnection <strong>and</strong> OleDbConnection classes derive from the DbConnection class, which implements<br />

the IDbConnection interface. The following table lists the database-specific classes.<br />

Classes<br />

desCriPTion<br />

SqlComm<strong>and</strong>, OleDbComm<strong>and</strong>, <strong>and</strong> ODBCComm<strong>and</strong> Used as wrappers for SQL statements or stored procedure<br />

calls. Examples for the SqlComm<strong>and</strong> class are shown later<br />

in the chapter.<br />

SqlComm<strong>and</strong>Builder, OleDbComm<strong>and</strong>Builder,<br />

<strong>and</strong> ODBCComm<strong>and</strong>Builder<br />

SqlConnection, OleDbConnection, <strong>and</strong><br />

ODBCConnection<br />

SqlDataAdapter, OleDbDataAdapter, <strong>and</strong><br />

ODBCDataAdapter<br />

SqlDataReader, OleDbDataReader, <strong>and</strong><br />

ODBCDataReader<br />

SqlParameter, OleDbParameter, <strong>and</strong><br />

ODBCParameter<br />

SqlTransaction, OleDbTransaction, <strong>and</strong><br />

ODBCTransaction<br />

Used to generate SQL comm<strong>and</strong>s (such as INSERT,<br />

UPDATE, <strong>and</strong> DELETE statements) from a SELECT<br />

statement.<br />

Used to connect to the database <strong>and</strong> is similar to an ADO<br />

connection. Examples are shown later in the chapter.<br />

Used to hold select, insert, update, <strong>and</strong> delete<br />

comm<strong>and</strong>s, which are then used to populate a<br />

DataSet <strong>and</strong> update the database. Examples of the<br />

SqlDataAdapter are presented in this chapter.<br />

Used as a forward-only, connected data reader. Some<br />

examples of the SqlDataReader are shown in this<br />

chapter.<br />

Used to define a parameter to a stored procedure.<br />

Examples of how to use the SqlParameter class are<br />

shown in this chapter.<br />

Used for a database transaction, wrapped in an object.<br />

The most important feature of the ADO.<strong>NET</strong> classes is that they are designed to work in a disconnected<br />

manner, which is important in today’s highly web-centric world. It is now common practice to architect a<br />

service (such as an online bookshop) to connect to a server, retrieve some data, <strong>and</strong> then work on that data<br />

on the client before reconnecting <strong>and</strong> passing the data back for processing. The disconnected nature of<br />

ADO.<strong>NET</strong> enables this type of behavior.<br />

Classic ADO 2.1 introduced the disconnected record set, which permits data to be retrieved from a<br />

database, passed to the client for processing, <strong>and</strong> then reattached to the server. This used to be cumbersome<br />

to use because disconnected behavior was not part of the original design. The ADO.<strong>NET</strong> classes are<br />

different — in all but one case (the [provider]DataReader), they are designed for use offline from<br />

the database.<br />

www.it-ebooks.info

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!