通过


DataTableCollection 类

定义

表示表 DataSet的集合。

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

示例

此示例中的第一个过程检索 DataTableCollection 一个 DataSet 列的值,并打印每个表的每一行的值。 第二个过程创建一个包含两列的新DataTable列,并将其添加到 。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特定DataSet对象的所有DataTable对象。 若要访问 DataTableCollection a DataSet,请使用该 Tables 属性。

该方法DataTableCollection使用方法,例如AddClear,并Remove管理集合中的项。

Contains使用该方法确定特定表(由索引或名称指定)是否在集合中。

若要从一个表导航到另一个表,请使用 ChildRelations 该表的或 ParentRelations 属性 DataTable 访问其对象集合 DataRelation 。 还可以使用该Relations属性浏览特定DataSet集合中的父/子关系DataTables

属性

名称 说明
Count

获取集合中的元素总数。

(继承自 InternalDataCollectionBase)
IsReadOnly

获取一个值,该值指示是否 InternalDataCollectionBase 为只读。

(继承自 InternalDataCollectionBase)
IsSynchronized

获取一个值,该值指示是否 InternalDataCollectionBase 同步。

(继承自 InternalDataCollectionBase)
Item[Int32]

DataTable获取指定索引处的对象。

Item[String, String]

DataTable获取指定命名空间中具有指定名称的对象。

Item[String]

DataTable获取具有指定名称的对象。

List

获取作为列表的集合的项。

List

获取作为列表的集合的项。

(继承自 InternalDataCollectionBase)
SyncRoot

获取可用于同步集合的对象。

(继承自 InternalDataCollectionBase)

方法

名称 说明
Add()

使用默认名称创建新 DataTable 对象,并将其添加到集合中。

Add(DataTable)

将指定的 DataTable 值添加到集合中。

Add(String, String)

使用指定的名称创建对象 DataTable ,并将其添加到集合中。

Add(String)

使用指定的名称创建对象 DataTable ,并将其添加到集合中。

AddRange(DataTable[])

将指定 DataTable 数组的元素复制到集合的末尾。

CanRemove(DataTable)

验证是否可以从集合中删除指定的 DataTable 对象。

Clear()

清除所有 DataTable 对象的集合。

Contains(String, String)

获取一个值,该值指示集合中是否存在 DataTable 具有指定名称和表命名空间的对象。

Contains(String)

获取一个值,该值指示集合中是否存在 DataTable 具有指定名称的对象。

CopyTo(Array, Int32)

从指定的InternalDataCollectionBase索引开始,将当前InternalDataCollectionBase的所有元素复制到一维Array

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

从指定的目标数组索引开始,将当前 DataTableCollection 的所有元素复制到一维 Array

Equals(Object)

确定指定的对象是否等于当前对象。

(继承自 Object)
GetEnumerator()

获取集合的一个 IEnumerator

(继承自 InternalDataCollectionBase)
GetHashCode()

用作默认哈希函数。

(继承自 Object)
GetType()

获取当前实例的 Type

(继承自 Object)
IndexOf(DataTable)

获取指定 DataTable 对象的索引。

IndexOf(String, String)

获取指定 DataTable 对象的集合中的索引。

IndexOf(String)

获取具有指定名称的对象集合 DataTable 中的索引。

MemberwiseClone()

创建当前 Object的浅表副本。

(继承自 Object)
OnCollectionChanged(CollectionChangeEventArgs)

引发 OnCollectionChanged(CollectionChangeEventArgs) 事件。

OnCollectionChanging(CollectionChangeEventArgs)

表示表 DataSet的集合。

Remove(DataTable)

从集合中删除指定的 DataTable 对象。

Remove(String, String)

DataTable 集合中删除具有指定名称的对象。

Remove(String)

DataTable 集合中删除具有指定名称的对象。

RemoveAt(Int32)

DataTable 集合中移除位于指定索引处的对象。

ToString()

返回一个表示当前对象的字符串。

(继承自 Object)

活动

名称 说明
CollectionChanged

由于DataTable添加或删除对象而更改后DataTableCollection发生。

CollectionChanging

DataTableCollection由于添加或删除的对象而DataTable更改时发生。

扩展方法

名称 说明
AsParallel(IEnumerable)

启用查询的并行化。

AsQueryable(IEnumerable)

IEnumerable 转换为 IQueryable

Cast<TResult>(IEnumerable)

IEnumerable 的元素强制转换为指定类型。

OfType<TResult>(IEnumerable)

根据指定类型筛选 IEnumerable 的元素。

适用于

线程安全性

此类型对于多线程读取操作是安全的。 必须同步任何写入操作。

另请参阅