| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
DataTableCollection ClassRepresents the collection of tables in a DataSet.
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Multicast | Name | Type |
|---|---|---|
| multicast | CollectionChanged | CollectionChangeEventHandler |
| multicast | CollectionChanging | CollectionChangeEventHandler |
The DataTableCollection contains all of the DataTable objects for a given DataSet. This collection is accessed via the DataSet.Tables property.
Like most data collections in ADO.NET, the DataTableCollection uses standard collection methods to manage the items in the collection. These include the methods Add, Clear, and Remove.
The collection also includes a Count property to determine how many DataTable objects are in the collection, and a Contains method to verify whether a particular table is in the collection.
To navigate from one table to another, use the ChildRelations or ParentRelations properties of the DataTable to access the table's collection of DataRelation objects. You can also navigate through the parent/child relationships of the tables in a given DataSet using the DataSet.Relations property.
The first example below retrieves the DataTableCollection of a DataSet and prints the value of each column, in each row, of each table. The second example initializes a new DataTable with two columns, and adds it to the DataTableCollection.
private void GetTables ( DataSet ds ) {
// get each DataTable in the DataTableCollection and print each row value.
foreach ( DataTable tbl in ds.Tables ) {
foreach ( DataRow row in tbl.Rows ) {
foreach ( DataColumn col in tbl.Columns ) {
if ( row [ col ] != null ) {
Response.Write ( row [ col ] );
}
}
}
}
}
private void CreateTable ( DataSet ds ) {
DataTable newTable = new DataTable ( "myTable" );
newTable.Columns.Add ( "ID", typeof ( int ) );
newTable.Columns.Add ( "Name", typeof ( string ) );
ds.Tables.Add ( newTable );
}
| ||
| C# | VB | |
DataColumn DataRow DataTable DataSet
Check out related books at Amazon
© 2000-2008 Rey Nuñez All rights reserved.
If you have any question, comment or suggestion
about this site, please send us a note
You can help support aspxtreme