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:
DataTable: A tabular representation of a data table containing rows and columns.
DataSet: A client representation of the data collected from a data source (known as a recordset in ADO). A DataSet is made up of a collection of DataTables. A DataSet can contain multiple tables from multiple sources.
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.
|
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. |
|
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. |