The DataTableClass
You use an object of theDataTableclass to represent a table. You can also store multiple
DataTable objects in a DataSet. Table 11.1
shows some of theDataTable properties.
Table 11.1: DataTable PROPERTIES
PROPERTY TYPE DESCRIPTION
CaseSensitive bool Gets or sets a bool value that indicates whether
string comparisons within DataTable objects are
case-sensitive.
ChildRelations DataRelationCollection Gets the collection of relations
(DataRelationCollection) that allows navigation
from a parent table to a child table. A
DataRelationCollection consists of DataRelation
objects.
Columns DataColumnCollection Gets the collection of columns
(DataColumnCollection) that contains
DataColumn objects that represent the columns
in theDataTable object.
Constraints ConstraintCollection Gets the collection of constraints
(ConstraintCollection) that contains Constraint
objects that represent primary key
(UniqueConstraint) or foreign key constraints
(ForeignKeyConstraint) in theDataTable object.
DataSet DataSet Gets the DataSet to which theDataTable
belongs.
HasErrors bool Returns a bool value that indicates whether any
of the rows in theDataTable have errors.
PrimaryKey DataColumn[] Gets or sets an array of DataColumn objects that
are the primary keys for the DataTable.
Rows DataRowCollection Gets the collection of rows (DataRowCollection)
that contains the DataRow objects stored in the
DataTable.
TableName string Gets or sets the name of theDataTable object.
Table 11.2 shows some of theDataTable methods.
Table 11.2: DataTable METHODS
METHOD RETURN
TYPE
DESCRIPTION
AcceptChanges() void Commits all the changes made to theDataTable object
since it was loaded or since the last time the
AcceptChanges() method was called.
Clear() void Removes all rows from theDataTable object.
Clone() DataTable Clones the structure of theDataTable object and returns
that clone.
Compute() object Computes the given expression on the current rows that
pass the filter criteria.
GetChanges() DataTable Overloaded. Returns a copy of theDataTable object since
it was last loaded or since the last time the
AcceptChanges() method was called.
GetErrors() DataRow[] Overloaded. Gets a copy of all the DataRow objects that
have errors.
LoadDataRow() DataRow Finds and updates a specified DataRow object. If no
matching object is found, a new row is created using the
specified values.
NewRow() DataRow Creates a new DataRow object in the DataTable.
RejectChanges() void Undoes all the changes made to theDataTable object
since it was created or since the last time the
AcceptChanges() method was called.
Select() DataRow[] Overloaded. Returns the array of DataRow objects stored
in theDataTable that match the specified filter string.
You can also pass a string containing details on how to
sort the DataRow objects.
Table 11.3 shows some of theDataTable events.
Table 11.3: DataTable EVENTS
EVENT EVENT HANDLER DESCRIPTION
ColumnChanging DataColumnChangeEventHandler Fires before a changed
DataColumn value is committed in
a DataRow.
ColumnChanged DataColumnChangeEventHandler Fires after a changed DataColumn
value is committed in a DataRow.
RowChanging DataRowChangeEventHandler Fires before a changed DataRow is
committed in a DataTable.
Table 11.3: DataTable EVENTS
EVENT EVENT HANDLER DESCRIPTION
RowChanged DataRowChangeEventHandler Fires after a changed DataRow is
committed in a DataTable.
RowDeleting DataRowChangeEventHandler Fires before a DataRow is deleted
from a DataTable.
RowDeleted DataRowChangeEventHandler Fires after a DataRow is deleted
from a DataTable.
.
The DataTable Class
You use an object of the DataTable class to represent a table. You can also store multiple
DataTable objects in. rows from the DataTable object.
Clone() DataTable Clones the structure of the DataTable object and returns
that clone.
Compute() object Computes the given