The ADO.NET Object Model
The
ADO.NET object model is rich, but at its heart it is a fairly
straightforward set of classes. The most important of these is the
DataSet
. The DataSet
represents a subset of the entire database, cached on your machine
without a continuous connection to the database.
Periodically, you’ll reconnect the
DataSet
to its parent database, update the
database with changes you’ve made to the
DataSet
, and update the DataSet
with changes in the database made by other processes.
This is highly efficient, but to be effective the
DataSet
must be a robust subset of the database,
capturing not just a few rows from a single table, but also a set of
tables with all the metadata necessary to represent the relationships
and constraints of the original database. This is, not surprisingly,
what ADO.NET provides.
The DataSet
is composed of
DataTable
objects as well as
DataRelation
objects. These are accessed as
properties of the DataSet
object. The
Tables
property returns a
DataTableCollection
,
which in turn contains all the DataTable
objects.
DataTables and DataColumns
The DataTable
can be created programmatically or
as a result of a query against the database. The
DataTable
has a number of public properties,
including the Columns
collection, which returns
the
DataColumnCollection
object, which in turn consists of
DataColumn
objects. Each
DataColumn
object represents a column in a table.
DataRelations
In addition to the Tables
collection, the
DataSet
has a Relations
Get Programming C#, Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.