DataTableCollection.Item[] プロパティ

定義

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

オーバーロード

Item[Int32]

指定したインデックス位置にある DataTable オブジェクトを取得します。

Item[String]

指定した名前の DataTable オブジェクトを取得します。

Item[String, String]

指定した名前の DataTable オブジェクトを、指定した名前空間から取得します。

Item[Int32]

指定したインデックス位置にある DataTable オブジェクトを取得します。

public:
 property System::Data::DataTable ^ default[int] { System::Data::DataTable ^ get(int index); };
public System.Data.DataTable this[int index] { get; }
member this.Item(int) : System.Data.DataTable
Default Public ReadOnly Property Item(index As Integer) As DataTable

パラメーター

index
Int32

検索する DataTable の 0 から始まるインデックスです。

プロパティ値

DataTable

指定したインデックスを持つ A DataTable 。それ null 以外の場合は DataTable 存在しません。

例外

インデックス値が、コレクション内の項目数を超える値です。

次の例では、インデックスによって a を DataTable 取得します。

private void GetDataTableByIndex()
{
   // presuming a DataGrid is displaying more than one table, get its DataSet.
   DataSet thisDataSet = (DataSet)DataGrid1.DataSource;
   // Get the DataTableCollection.
   DataTableCollection tablesCollection = thisDataSet.Tables;
   // Iterate through the collection to get each table name.
   for (int i = 0; i < tablesCollection.Count; i++)
      Console.WriteLine(tablesCollection[i].TableName);
}
Private Sub GetDataTableByIndex()
    ' Presuming a DataGrid is displaying more than one table, get its DataSet.
    Dim thisDataSet As DataSet = CType(DataGrid1.DataSource, DataSet)

    ' Get the DataTableCollection.
    Dim tablesCollection As DataTableCollection = thisDataSet.Tables

    ' Iterate through the collection to get each table name.
    Dim i As Integer
    For i = 0 To tablesCollection.Count - 1
       Console.WriteLine(tablesCollection(i).TableName)
    Next
End Sub

注釈

特定のインデックスを Contains 持つテーブルが存在するかどうかを判断するには、このメソッドを使用します。

テーブルの名前を持っていて、インデックスがない場合は、メソッドを IndexOf 使用してインデックスを返します。

こちらもご覧ください

適用対象

Item[String]

指定した名前の DataTable オブジェクトを取得します。

public:
 property System::Data::DataTable ^ default[System::String ^] { System::Data::DataTable ^ get(System::String ^ name); };
public System.Data.DataTable? this[string? name] { get; }
public System.Data.DataTable this[string name] { get; }
member this.Item(string) : System.Data.DataTable
Default Public ReadOnly Property Item(name As String) As DataTable

パラメーター

name
String

検索する DataTable の名前です。

プロパティ値

DataTable

指定した名前の DataTable。そのような DataTable が存在しない場合は null

次の例では、.. から名前で 1 つのテーブルを DataTableCollection取得します。

private void GetTableByName()
{
    // Presuming a DataGrid is displaying more than one table, get its DataSet.
    DataSet thisDataSet = (DataSet)DataGrid1.DataSource;

    // Get the DataTableCollection.
    DataTableCollection tablesCollection = thisDataSet.Tables;

    // Get a specific table by name.
    DataTable table = tablesCollection["Suppliers"];
    Console.WriteLine(table.TableName);
}
Private Sub GetTableByName()
    ' Presuming a DataGrid is displaying more than one table, 
    ' get its DataSet.
    Dim thisDataSet As DataSet = CType(DataGrid1.DataSource, DataSet)

    ' Get the DataTableCollection.
    Dim tablesCollection As DataTableCollection = thisDataSet.Tables

    ' Get a specific table by name.
    Dim table As DataTable = tablesCollection("Suppliers")
    Console.WriteLine(table.TableName)
End Sub

注釈

検索文字列の大文字と DataTable 小文字が一致する名前が存在する場合は、その名前が返されます。 それ以外の場合は、大文字と小文字を区別しない検索が実行され、この検索に一致する名前が見つかった場合 DataTable は返されます。

このメソッドを Contains 使用して、特定の名前またはインデックスを持つテーブルが存在するかどうかを判断します。

適用対象

Item[String, String]

指定した名前の DataTable オブジェクトを、指定した名前空間から取得します。

public:
 property System::Data::DataTable ^ default[System::String ^, System::String ^] { System::Data::DataTable ^ get(System::String ^ name, System::String ^ tableNamespace); };
public System.Data.DataTable? this[string? name, string tableNamespace] { get; }
public System.Data.DataTable this[string name, string tableNamespace] { get; }
member this.Item(string * string) : System.Data.DataTable
Default Public ReadOnly Property Item(name As String, tableNamespace As String) As DataTable

パラメーター

name
String

検索する DataTable の名前です。

tableNamespace
String

検索する DataTable 名前空間の名前。

プロパティ値

DataTable

指定した名前の DataTable。そのような DataTable が存在しない場合は null

適用対象