Represents the collection of tables for the DataSet.
For a list of all members of this type, see DataTableCollection Members.
System.Object
System.Data.InternalDataCollectionBase
System.Data.DataTableCollection
[Visual Basic] <Serializable> Public Class DataTableCollection Inherits InternalDataCollectionBase [C#] [Serializable] public class DataTableCollection : InternalDataCollectionBase [C++] [Serializable] public __gc class DataTableCollection : public InternalDataCollectionBase [JScript] public Serializable class DataTableCollection extends InternalDataCollectionBase
This type is safe for multithreaded read operations. You must synchronize any write operations.
The DataTableCollection contains all of 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 if 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 given DataSet collection.
[Visual Basic, C#] 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 creates a new DataTable with two columns, and adds it to the DataTableCollection.
[Visual Basic] Private Sub GetTables(ds As DataSet) ' Get Each DataTable in the DataTableCollection and print each row value. Dim t As DataTable Dim r As DataRow Dim c As DataColumn For Each t In ds.Tables For Each r In t.Rows For Each c in t.Columns If Not (r(c) Is Nothing) Then Console.WriteLine(r(c)) End If Next Next Next End Sub Private Sub CreateTable(ds As DataSet) Dim newTable As DataTable = new DataTable("MyTable") newTable.Columns.Add("ID", Type.GetType("System.Int32")) newTable.Columns.Add("Name", Type.GetType("System.String")) ds.Tables.Add(newTable) End Sub [C#] private void GetTables(DataSet ds) { // Get Each DataTable in the DataTableCollection and print each row value. foreach (DataTable t in ds.Tables) foreach (DataRow r in t.Rows) foreach (DataColumn c in t.Columns) if (r[c] != null) Console.WriteLine(r[c]); } 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++, JScript] No example is available for C++ or JScript. To view a Visual Basic or C# example, click the Language Filter button
in the upper-left corner of the page.
Namespace: System.Data
Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework - Windows CE .NET
Assembly: System.Data (in System.Data.dll)
DataTableCollection Members | System.Data Namespace | DataColumn | DataRow | DataTable | DataSet