共用方式為


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
屬性

範例

本範例中的第一個程序是取得 a DataSet 的 ,DataTableCollection並列印每個資料表每一列的值。 第二個程序是建立一個有兩欄的新資料 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

備註

包含DataTableCollectionDataTable特定 DataSet的所有物件。 要存取 DataTableCollectionDataSet,請使用該物業。Tables

該方法 DataTableCollection 使用如 AddClearRemove 等方法來管理集合中的項目。

使用此 Contains 方法判斷特定資料表(由索引或名稱指定)是否在集合中。

要從一個資料表移動到另一個資料表,請使用 ChildRelationsDataTableParentRelations 屬性來存取其物件集合DataRelation。 你也可以用這個Relations屬性來瀏覽特定DataSet集合中 的DataTables父子關係。

屬性

名稱 Description
Count

取得集合中元素的總數。

(繼承來源 InternalDataCollectionBase)
IsReadOnly

會得到一個值,表示 是否 InternalDataCollectionBase 為唯讀。

(繼承來源 InternalDataCollectionBase)
IsSynchronized

會得到一個表示是否 InternalDataCollectionBase 同步的值。

(繼承來源 InternalDataCollectionBase)
Item[Int32]

取得 DataTable 指定索引的物件。

Item[String, String]

取得 DataTable 指定命名空間中擁有指定名稱的物件。

Item[String]

取得 DataTable 指定名稱的物件。

List

會把收藏品當成清單。

List

會把收藏品當成清單。

(繼承來源 InternalDataCollectionBase)
SyncRoot

取得一個可以用來同步集合的物件。

(繼承來源 InternalDataCollectionBase)

方法

名稱 Description
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 中的所有元素複製到一維 Array,從指定的 InternalDataCollectionBase 索引開始。

(繼承來源 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)

事件

名稱 Description
CollectionChanged

發生在 DataTableCollection 物件被新增 DataTable 或移除後。

CollectionChanging

發生在物件 DataTableCollectionDataTable 新增或移除時。

擴充方法

名稱 Description
AsParallel(IEnumerable)

啟用查詢的平行處理。

AsQueryable(IEnumerable)

IEnumerable 轉換成 IQueryable

Cast<TResult>(IEnumerable)

IEnumerable 的項目轉換成指定的型別。

OfType<TResult>(IEnumerable)

根據指定的型別篩選 IEnumerable 的專案。

適用於

執行緒安全性

此類型適合多執行緒讀取操作。 你必須同步所有寫入操作。

另請參閱