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

この例の最初のDataSetプロシージャは、a の値をDataTableCollection取得し、各テーブルの各行の各列の値を出力します。 2 番目の手順では、2 つの列を含む新しい 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含まれます。 のDataSetプロパティにDataTableCollectionアクセスするには、プロパティを使用しますTables

DataTableCollectionなどのAddClearメソッドを使用しRemove、コレクション内の項目を管理します。

このメソッドを Contains 使用して、特定のテーブル (インデックスまたは名前で指定) がコレクション内にあるかどうかを判断します。

あるテーブルから別のテーブルに移動するには、オブジェクトのコレクションにChildRelationsアクセスするために、そのDataTableテーブルの DataRelation or ParentRelations プロパティを使用します。 また、このプロパティを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)

指定した名前を使用して DataTable オブジェクトを作成し、このオブジェクトをコレクションに追加します。

Add(String, String)

指定した名前を使用して DataTable オブジェクトを作成し、このオブジェクトをコレクションに追加します。

AddRange(DataTable[])

指定した DataTable 配列の要素をコレクションの末尾にコピーします。

CanRemove(DataTable)

指定した DataTable オブジェクトをコレクションから削除できるかどうかを確認します。

Clear()

すべての DataTable オブジェクトをコレクションから削除します。

Contains(String)

指定した名前の DataTable オブジェクトがコレクション内に存在するかどうかを示す値を取得します。

Contains(String, String)

指定した名前の DataTable オブジェクト、およびテーブルの名前空間がコレクション内に存在するかどうかを示す値を取得します。

CopyTo(Array, Int32)

現在の InternalDataCollectionBase のすべての要素を 1 次元の Array にコピーします。コピー操作は、指定した InternalDataCollectionBase インデックスから始まります。

(継承元 InternalDataCollectionBase)
CopyTo(DataTable[], Int32)

指定したコピー先の配列のインデックスを開始位置として、現在の DataTableCollection のすべての要素を 1 次元の Array にコピーします。

Equals(Object)

指定されたオブジェクトが現在のオブジェクトと等しいかどうかを判断します。

(継承元 Object)
GetEnumerator()

コレクションの IEnumerator を取得します。

(継承元 InternalDataCollectionBase)
GetHashCode()

既定のハッシュ関数として機能します。

(継承元 Object)
GetType()

現在のインスタンスの Type を取得します。

(継承元 Object)
IndexOf(DataTable)

指定した DataTable オブジェクトのインデックスを取得します。

IndexOf(String)

コレクション内の、指定した名前の DataTable オブジェクトのインデックスを取得します。

IndexOf(String, String)

指定した DataTable オブジェクトのコレクション内のインデックスを取得します。

MemberwiseClone()

現在の Object の簡易コピーを作成します。

(継承元 Object)
OnCollectionChanged(CollectionChangeEventArgs)

OnCollectionChanged(CollectionChangeEventArgs) イベントを発生させます。

OnCollectionChanging(CollectionChangeEventArgs)
Remove(DataTable)

指定した DataTable オブジェクトをコレクションから削除します。

Remove(String)

指定した名前を持つ DataTable オブジェクトをコレクションから削除します。

Remove(String, String)

指定した名前を持つ DataTable オブジェクトをコレクションから削除します。

RemoveAt(Int32)

指定したインデックス位置にある DataTable オブジェクトをコレクションから削除します。

ToString()

現在のオブジェクトを表す文字列を返します。

(継承元 Object)

events

CollectionChanged

DataTableCollection オブジェクトを追加または削除したことが原因で DataTable が変更された後に発生します。

CollectionChanging

DataTableCollection オブジェクトを追加または削除したことが原因で DataTable が変更されているときに発生します。

拡張メソッド

Cast<TResult>(IEnumerable)

IEnumerable の要素を、指定した型にキャストします。

OfType<TResult>(IEnumerable)

指定された型に基づいて IEnumerable の要素をフィルター処理します。

AsParallel(IEnumerable)

クエリの並列化を有効にします。

AsQueryable(IEnumerable)

IEnumerableIQueryable に変換します。

適用対象

スレッド セーフ

この型は、マルチスレッド読み取り操作では安全です。 すべての書き込み操作を同期する必要があります。

こちらもご覧ください