DataTableCollection Class
TOC
Collapse the table of content
Expand the table of content

DataTableCollection Class

Represents the collection of tables for the DataSet.

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

'Declaration
Public NotInheritable Class DataTableCollection
	Inherits InternalDataCollectionBase
'Usage
Dim instance As DataTableCollection

public final class DataTableCollection extends InternalDataCollectionBase
public final class DataTableCollection extends InternalDataCollectionBase
Not applicable.

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

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

Windows 98, Windows Server 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 Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

XNA Framework

Supported in: 1.0

Community Additions

ADD
Show:
© 2016 Microsoft