DataTableCollection 类

定义

表示 DataSet 的表的集合。Represents the collection of tables for the DataSet.

public ref class DataTableCollection sealed : System::Data::InternalDataCollectionBase
[System.ComponentModel.ListBindable(false)]
[System.Serializable]
public sealed class DataTableCollection : System.Data.InternalDataCollectionBase
type DataTableCollection = class
    inherit InternalDataCollectionBase
Public NotInheritable Class DataTableCollection
Inherits InternalDataCollectionBase
继承
DataTableCollection
属性

示例

此示例中的第一个过程检索DataTableCollection DataSet的,并打印每个表的每一行的值。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. 第二个过程创建一个DataTable具有两列的新,并将其DataTableCollection添加到中。The second procedure creates a new DataTable with two columns, and adds it to the DataTableCollection.

private void GetTables(DataSet dataSet)
{
    // Get Each DataTable in the DataTableCollection and 
    // print each row value.
    foreach (DataTable table in dataSet.Tables)
        foreach (DataRow row in table.Rows)
            foreach (DataColumn column in table.Columns)
                if (row[column] != null)
                    Console.WriteLine(row[column]);
}

private void CreateTable(DataSet dataSet)
{
    DataTable newTable = new DataTable("table");
    newTable.Columns.Add("ID", typeof(int));
    newTable.Columns.Add("Name", typeof(string));
    dataSet.Tables.Add(newTable);
}
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 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

注解

DataTableCollection包含DataTable特定的DataSet所有对象。The DataTableCollection contains all the DataTable objects for a particular DataSet. 若要访问DataTableCollection DataSet的,请使用Tables属性。To access the DataTableCollection of a DataSet, use the Tables property.

使用方法(如Clear、和Remove )来管理集合中的项。 Add DataTableCollectionThe DataTableCollection uses methods such as Add, Clear, and Remove to manage the items in the collection.

Contains使用方法来确定特定表(由索引或名称指定)是否在集合中。Use the Contains method to determine whether a particular table (specified by either index or name) is in the collection.

若要从一个表导航到另一个表ChildRelationsParentRelations请使用的DataTable或属性来访问其DataRelation对象集合。To navigate from one table to another, use the ChildRelations or ParentRelations property of the DataTable to access its collection of DataRelation objects. 你还可以使用Relations属性来浏览特定DataSet集合中的的DataTables父/子关系。You can also use the Relations property to navigate through the parent/child relationships of the DataTables in a particular DataSet collection.

属性

Count

获取集合中的元素总数。Gets the total number of elements in a collection.

(继承自 InternalDataCollectionBase)
IsReadOnly

获取一个值,该值指示 InternalDataCollectionBase 是否为只读。Gets a value that indicates whether the InternalDataCollectionBase is read-only.

(继承自 InternalDataCollectionBase)
IsSynchronized

获取一个值,该值指示 InternalDataCollectionBase 是否已同步。Gets a value that indicates whether the InternalDataCollectionBase is synchronized.

(继承自 InternalDataCollectionBase)
Item[Int32]

获取位于指定索引位置的 DataTable 对象。Gets the DataTable object at the specified index.

Item[String, String]

获取指定命名空间中具有指定名称的 DataTable 对象。Gets the DataTable object with the specified name in the specified namespace.

Item[String]

获取具有指定名称的 DataTable 对象。Gets the DataTable object with the specified name.

List

获取作为列表的集合的项。Gets the items of the collection as a list.

(继承自 InternalDataCollectionBase)
SyncRoot

获取可用于同步集合的对象。Gets an object that can be used to synchronize the collection.

(继承自 InternalDataCollectionBase)

方法

Add()

使用默认名称创建一个新的 DataTable 对象,并将其添加到集合中。Creates a new DataTable object by using a default name and adds it to the collection.

Add(DataTable)

将指定的 DataTable 添加到集合。Adds the specified DataTable to the collection.

Add(String)

使用指定名称创建一个 DataTable 对象,并将其添加到集合中。Creates a DataTable object by using the specified name and adds it to the collection.

Add(String, String)

使用指定名称创建一个 DataTable 对象,并将其添加到集合中。Creates a DataTable object by using the specified name and adds it to the collection.

AddRange(DataTable[])

将指定的 DataTable 数组的元素复制到集合末尾。Copies the elements of the specified DataTable array to the end of the collection.

CanRemove(DataTable)

验证是否可以将指定的 DataTable 对象从集合中移除。Verifies whether the specified DataTable object can be removed from the collection.

Clear()

清除所有 DataTable 对象的集合。Clears the collection of all DataTable objects.

Contains(String)

获取一个值,该值指示集合中是否存在具有指定名称的 DataTable 对象。Gets a value that indicates whether a DataTable object with the specified name exists in the collection.

Contains(String, String)

获取一个值,该值指示集合中是否存在具有指定名称和表命名空间的 DataTable 对象。Gets a value that indicates whether a DataTable object with the specified name and table namespace exists in the collection.

CopyTo(Array, Int32)

将当前 InternalDataCollectionBase 的所有元素复制到一维 Array,从指定的 InternalDataCollectionBase 索引开始。Copies all the elements of the current InternalDataCollectionBase to a one-dimensional Array, starting at the specified InternalDataCollectionBase index.

(继承自 InternalDataCollectionBase)
CopyTo(DataTable[], Int32)

将当前 DataTableCollection 的所有元素复制到一维 Array,从指定目标数组索引处开始。Copies all the elements of the current DataTableCollection to a one-dimensional Array, starting at the specified destination array index.

Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(继承自 Object)
GetEnumerator()

获取集合的 IEnumeratorGets an IEnumerator for the collection.

(继承自 InternalDataCollectionBase)
GetHashCode()

作为默认哈希函数。Serves as the default hash function.

(继承自 Object)
GetType()

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)
IndexOf(DataTable)

获取指定 DataTable 对象的索引。Gets the index of the specified DataTable object.

IndexOf(String)

获取具有指定名称的 DataTable 对象的集合中的索引。Gets the index in the collection of the DataTable object with the specified name.

IndexOf(String, String)

获取指定 DataTable 对象的集合中的索引。Gets the index in the collection of the specified DataTable object.

MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)
Remove(DataTable)

从集合中移除指定的 DataTable 对象。Removes the specified DataTable object from the collection.

Remove(String)

从集合中删除具有指定名称的 DataTable 对象。Removes the DataTable object with the specified name from the collection.

Remove(String, String)

从集合中删除具有指定名称的 DataTable 对象。Removes the DataTable object with the specified name from the collection.

RemoveAt(Int32)

从集合中移除位于指定索引位置的 DataTable 对象。Removes the DataTable object at the specified index from the collection.

ToString()

返回表示当前对象的字符串。Returns a string that represents the current object.

(继承自 Object)

事件

CollectionChanged

由于添加或移除 DataTableCollection 对象而更改 DataTable 之后发生。Occurs after the DataTableCollection is changed because of DataTable objects being added or removed.

CollectionChanging

由于添加或移除 DataTableCollection 对象而更改 DataTable 时发生。Occurs while the DataTableCollection is changing because of DataTable objects being added or removed.

扩展方法

Cast<TResult>(IEnumerable)

IEnumerable 的元素强制转换为指定的类型。Casts the elements of an IEnumerable to the specified type.

OfType<TResult>(IEnumerable)

根据指定类型筛选 IEnumerable 的元素。Filters the elements of an IEnumerable based on a specified type.

AsParallel(IEnumerable)

启用查询的并行化。Enables parallelization of a query.

AsQueryable(IEnumerable)

IEnumerable 转换为 IQueryableConverts an IEnumerable to an IQueryable.

适用于

线程安全性

对于多线程读取操作,此类型是安全的。This type is safe for multithreaded read operations. 必须同步任何写入操作。You must synchronize any write operations.

另请参阅