次の方法で共有


DataTableCollection.Item プロパティ (Int32)

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

[C#] C# では、このプロパティは DataTableCollection クラスのインデクサになります。

Overloads Public Default ReadOnly Property Item( _
   ByVal index As Integer _) As DataTable
[C#]
public DataTable this[intindex] {get;}
[C++]
public: __property DataTable* get_Item(intindex);
[JScript]
returnValue = DataTableCollectionObject.Item(index);またはreturnValue = DataTableCollectionObject(index);

[JScript] JScript では、この型で定義されている既定のインデックス プロパティを使用することができます。しかし、独自のインデックス プロパティを明示的に定義することはできません。ただし、このクラスの expando 属性を指定すると、既定のインデックス プロパティが提供されます。提供されるインデックス プロパティの型は Object 型であり、インデックス型は String になります。

引数 [JScript]

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

パラメータ [Visual Basic, C#, C++]

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

プロパティ値

DataTable

例外

例外の種類 条件
IndexOutOfRangeException インデックス値が、コレクション内の項目数を超える値です。

解説

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

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

使用例

[Visual Basic, C#, C++] インデックスで DataTable を取得する例を次に示します。

 
Private Sub GetDataTableByIndex()
   ' Presuming a DataGrid is displaying more than one table, get its DataSet.
   Dim dSet As DataSet = CType(DataGrid1.DataSource, DataSet)
   ' Get the DataTableCollection.
   Dim tablesCol As DataTableCollection = dSet.Tables
   ' Iterate through the collection to get each table name.
   Dim i As Integer
   For i = 0 To tablesCol.Count - 1
      Console.WriteLine(tablesCol(i).TableName)
   Next
End Sub

[C#] 
private void GetDataTableByIndex()
{
   // presuming a DataGrid is displaying more than one table, get its DataSet.
   DataSet dSet = (DataSet)DataGrid1.DataSource;
   // Get the DataTableCollection.
   DataTableCollection tablesCol = dSet.Tables;
   // Iterate through the collection to get each table name.
   for (int i = 0; i < tablesCol.Count; i++)
      Console.WriteLine(tablesCol[i].TableName);
}

[C++] 
private:
 void GetDataTableByIndex()
 {
    // presuming a DataGrid is displaying more than one table, get its DataSet.
    DataSet* dSet = dynamic_cast<DataSet*>(DataGrid1->DataSource);
    // Get the DataTableCollection.
    DataTableCollection* tablesCol = dSet->Tables;
    // Iterate through the collection to get each table name.
    for (int i = 0; i < tablesCol->Count; i++)
       Console::WriteLine(tablesCol->Item[i]->TableName);
 }

[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ

参照

DataTableCollection クラス | DataTableCollection メンバ | System.Data 名前空間 | DataTableCollection.Item オーバーロードの一覧 | Contains | IndexOf | DataTable