Name
DataTable
Synopsis
The DataTable
object contains the schema and data
for a single table. Column settings, such as column names and data
types are specified using the DataColumn
objects
contained in the table and accessed using the
Columns
property. Each row of data is encapsulated
within a separate DataRow
object, which is
accessed using the Rows
property. Also,
ForeignKeyConstraint
and
UniqueConstraint
objects can be added to the
ConstraintCollection
for the table, which is
accessed using the Constraints
property.
The DataTable
provides many of the same methods as
the DataSet
. For example, you can use
Copy( )
, Clone( )
,
Clear( )
, GetChanges( )
,
HasErrors
, and AcceptChanges( )
in the same way as described for the
DataSet
. In addition, you can use the
Select( )
method to retrieve an array of
DataRow
objects that match a specified SQL filter
expression. There are four overloaded versions of the
Select( )
method, some of which allow you to
specify a sort order and filter based on the
DataRowState
of the DataRow
.
Finally, you can use the NewRow( )
method to
generate a new DataRow
object that has the same
schema as the DataTable
. This is detached row;
once you have finished entering the required information you must add
it to the RowCollection
.
The DataTable
has six events that allow you to
react when column values are changed. You can handle
RowChanging
to implement row-specific validation
rules or handle ColumnChanging
to implement column-specific validation rules. Both events fire ...
Get ADO.NET in a Nutshell 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.