DataTableCollection Class

Represents the collection of tables for the DataSet.

Namespace: System.Data
Assembly: System.Data (in

Public NotInheritable Class DataTableCollection
	Inherits InternalDataCollectionBase
Dim instance As DataTableCollection

public final class DataTableCollection extends InternalDataCollectionBase
public final class DataTableCollection extends InternalDataCollectionBase

The DataTableCollection contains all the DataTable objects for a particular DataSet. To access the DataTableCollection of a DataSet, use the Tables property.

The DataTableCollection uses methods such as Add, Clear, and Remove to manage the items in the collection.

Use the Contains method to determine whether a particular table (specified by either index or name) is in the collection.

To navigate from one table to another, use the ChildRelations or ParentRelations property of the DataTable to access its collection of DataRelation objects. You can also use the Relations property to navigate through the parent/child relationships of the DataTables in a particular DataSet collection.

The first procedure in this example retrieves the DataTableCollection of a DataSet and prints the value of each column, in each row, of each table. The second procedure creates a new DataTable with two columns, and adds it to the DataTableCollection.

Private Sub GetTables(dataSet As DataSet)
   ' Get Each DataTable in the DataTableCollection and 
   ' print each row value.
   Dim table As DataTable
   Dim row As DataRow
   Dim column As DataColumn
   For Each table In dataSet.Tables
      For Each row In table.Rows
         For Each column in table.Columns
            If Not (row(column) Is Nothing) Then
            End If
End Sub

Private Sub CreateTable(dataSet As DataSet)
   Dim newTable As DataTable = new DataTable("table")
   newTable.Columns.Add("ID", Type.GetType("System.Int32"))
   newTable.Columns.Add("Name", Type.GetType("System.String"))
End Sub

This type is safe for multithreaded read operations. You must synchronize any write operations.

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

Community Additions