Represents the collection of tables for the DataSet.
Object
BaseCollection
TablesCollection
[Visual Basic] Public Class TablesCollection Inherits BaseCollection [C#] public class TablesCollection : BaseCollection [C++] public __gc class TablesCollection : public BaseCollection [JScript] public class TablesCollection extends BaseCollection
The TablesCollection contains all of the DataTable objects for a DataSet. To access the TablesCollection of a DataSet, use the Tables property.
The TablesCollection has the standard collection methods Add, Clear, and Remove as well as an All method to return the collection as an array.
To determine if a particular table (specified by either index or name) is in the collection, the Contains method returns a boolean value.
To navigate from one table to another, use the DataTable class's ChildRelations or ParentRelations properties to access the table's collection of DataRelation objects. You can also navigate through the DataSet class's collection using the Relations property.
Namespace: System.Data
Assembly: System.Data.dll
The first example below retrieves the TablesCollection 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 TablesCollection.
[Visual Basic]
Private Sub GetTables() Dim ds As DataSet ' Assuming a DataGrid bound to a DataSet. ds = DataGrid1.DataSource ' Get Each DataTable in the TablesCollection 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 IsNull(r(c)) Then Console.WriteLine r(c) Next Next Next End Sub
TablesCollection Members | System.Data Namespace | DataColumn | DataRow | DataTable | DataSet