O'Reilly logo

ADO.NET in a Nutshell by Bill Hamilton, Matthew MacDonald

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required