Team LiB
Previous Section Next Section

Chapter 13: ADO.NET

Basic ADO.NET Concepts

There are two ways to use a database: connected and disconnected. The connected method makes use of the XXXConnection, XXXCommand, and XXXDataReader classes. The disconnected state uses the XXXDataAdapter class in conjunction with the same three classes used by the connected method, as well as a DataSet.

ADO.NET has two basic components:

Data providers allow access to specific kinds of databases. These include SQL ( SqlClient ), OLE DB ( Oledb ), and ODBC ( Odbc ) databases. The data providers are made up of a consistent set of classes based on the classes shown in Table 13-1. Table 13-2 shows the common System.Data classes used to work with data tables.

Table 13-1: Main Database Access Classes

Class

Description

Connection

Used to connect to the data sources.

Command

Used for command execution. For example, the ExecuteReader method returns a DataReader, the ExecuteScalar method returns a single value, and ExecuteNonQuery is used when no data will be returned (such as in an UPDATE statement).

DataReader

Forwards read-only connection results.

DataAdapter

Used to populate or update a data set. This acts as a bridge between the data set and the data source. SelectCommand retrieves data, InsertCommand adds a new record, UpdateCommand updates an existing record, and DeleteCommand deletes a record.

Table 13-2: System.Data Common Classes

Class

Description

Constraint

Represents a constraint that can be applied to DataColumn objects

ConstraintCollection

DataTable collection of constraint objects

DataColumn

DataTable column schema

DataColumnCollection

Collection of DataColumn objects

DataRelation

Represents a parent-child relationship between two tables

DataRelationCollection

Collection of DataRelation objects

DataRow

Represents a row of data in a table

DataRowCollection

Collection of DataRow objects

DataRowView

Contains properties of a view of a data row

DataSet

Represents an in-memory version of one or more tables

DataTable

Represents an in-memory version of a table

DataView

Represents a view of a DataTable

DataViewManager

Contains a default view of a DataTable

Note?/td>

Table 13-1 shows generic names for the classes. The actual implementations of these classes are named after their data provider. For example, the SQL Connection class is called SqlConnection, and the OLE DB Connection class is called OledbConnection.


Team LiB
Previous Section Next Section