Export (0) Print
Expand All

DataTableCollection Class

Represents the collection of tables for the DataSet.

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

'Declaration
<ListBindableAttribute(False)> _
Public NotInheritable Class DataTableCollection _
	Inherits InternalDataCollectionBase

The DataTableCollection type exposes the following members.

  NameDescription
Public propertySupported by the XNA FrameworkCountGets the total number of elements in a collection. (Inherited from InternalDataCollectionBase.)
Public propertySupported by the XNA FrameworkIsReadOnlyGets a value that indicates whether the InternalDataCollectionBase is read-only. (Inherited from InternalDataCollectionBase.)
Public propertySupported by the XNA FrameworkIsSynchronizedGets a value that indicates whether the InternalDataCollectionBase is synchonized. (Inherited from InternalDataCollectionBase.)
Public propertySupported by the XNA FrameworkItem(Int32)Gets the DataTable object at the specified index.
Public propertySupported by the XNA FrameworkItem(String)Gets the DataTable object with the specified name.
Public propertySupported by the XNA FrameworkItem(String, String)Gets the DataTable object with the specified name in the specified namespace.
Public propertySupported by the XNA FrameworkSyncRootGets an object that can be used to synchronize the collection. (Inherited from InternalDataCollectionBase.)
Top

  NameDescription
Public methodSupported by the XNA FrameworkAddCreates a new DataTable object by using a default name and adds it to the collection.
Public methodSupported by the XNA FrameworkAdd(DataTable)Adds the specified DataTable to the collection.
Public methodSupported by the XNA FrameworkAdd(String)Creates a DataTable object by using the specified name and adds it to the collection.
Public methodSupported by the XNA FrameworkAdd(String, String)Creates a DataTable object by using the specified name and adds it to the collection.
Public methodSupported by the XNA FrameworkAddRangeCopies the elements of the specified DataTable array to the end of the collection.
Public methodSupported by the XNA FrameworkCanRemoveVerifies whether the specified DataTable object can be removed from the collection.
Public methodSupported by the XNA FrameworkClearClears the collection of all DataTable objects.
Public methodSupported by the XNA FrameworkContains(String)Gets a value that indicates whether a DataTable object with the specified name exists in the collection.
Public methodSupported by the XNA FrameworkContains(String, String)Gets a value that indicates whether a DataTable object with the specified name and table namespace exists in the collection.
Public methodSupported by the XNA FrameworkCopyTo(Array, Int32)Copies all the elements of the current InternalDataCollectionBase to a one-dimensional Array, starting at the specified InternalDataCollectionBase index. (Inherited from InternalDataCollectionBase.)
Public methodSupported by the XNA FrameworkCopyTo(DataTable(), Int32)Copies all the elements of the current DataTableCollection to a one-dimensional Array, starting at the specified destination array index.
Public methodSupported by the XNA FrameworkEquals(Object)Determines whether the specified object is equal to the current object. (Inherited from Object.)
Public methodSupported by the XNA FrameworkGetEnumeratorGets an IEnumerator for the collection. (Inherited from InternalDataCollectionBase.)
Public methodSupported by the XNA FrameworkGetHashCodeServes as the default hash function. (Inherited from Object.)
Public methodSupported by the XNA FrameworkGetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodSupported by the XNA FrameworkIndexOf(DataTable)Gets the index of the specified DataTable object.
Public methodSupported by the XNA FrameworkIndexOf(String)Gets the index in the collection of the DataTable object with the specified name.
Public methodSupported by the XNA FrameworkIndexOf(String, String)Gets the index in the collection of the specified DataTable object.
Public methodSupported by the XNA FrameworkRemove(DataTable)Removes the specified DataTable object from the collection.
Public methodSupported by the XNA FrameworkRemove(String)Removes the DataTable object with the specified name from the collection.
Public methodSupported by the XNA FrameworkRemove(String, String)Removes the DataTable object with the specified name from the collection.
Public methodSupported by the XNA FrameworkRemoveAtRemoves the DataTable object at the specified index from the collection.
Public methodSupported by the XNA FrameworkToStringReturns a string that represents the current object. (Inherited from Object.)
Top

  NameDescription
Public eventSupported by the XNA FrameworkCollectionChangedOccurs after the DataTableCollection is changed because of DataTable objects being added or removed.
Public eventSupported by the XNA FrameworkCollectionChangingOccurs while the DataTableCollection is changing because of DataTable objects being added or removed.
Top

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
               Console.WriteLine(row(column))
            End If 
         Next 
      Next 
   Next 
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"))
   dataSet.Tables.Add(newTable)
End Sub

.NET Framework

Supported in: 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

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

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

Show:
© 2014 Microsoft