asp.net.ph

DataTableCollection Class

System.Data Namespace


Represents the collection of tables in a DataSet.

DataTableCollection Class Members

Collapse   Properties

Visibility Name Value Type Accessibility
public Item ( String name ) ( String tableNamespace ) DataTable [ Get ]
public Item ( String name ) DataTable [ Get ]
public Item ( Int32 index ) DataTable [ Get ]

Collapse   Methods

Visibility Name Parameters Return Type
public Add ( String name , String tableNamespace ) DataTable
public Add ( ) DataTable
public Add ( String name ) DataTable
public Add ( DataTable table ) Void
public AddRange ( DataTable tables ) Void
public CanRemove ( DataTable table ) Boolean
public Clear ( ) Void
public Contains ( String name , String tableNamespace ) Boolean
public Contains ( String name ) Boolean
public CopyTo ( DataTable array , Int32 index ) Void
public IndexOf ( String tableName , String tableNamespace ) Int32
public IndexOf ( String tableName ) Int32
public IndexOf ( DataTable table ) Int32
public Remove ( String name ) Void
public Remove ( String name , String tableNamespace ) Void
public Remove ( DataTable table ) Void
public RemoveAt ( Int32 index ) Void

Remarks

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.

Example

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

See Also

DataColumn   DataRow   DataTable   DataSet Skip Navigation Links




Home
Suggested Reading


Previous page Back to top Next page

© 2000-2010 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 asp.net.ph