次の方法で共有


DataRowCollection.Item プロパティ

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

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

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

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

引数 [JScript]

  • index
    返す行の 0 から始まるインデックス番号。

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

  • index
    返す行の 0 から始まるインデックス番号。

プロパティ値

指定した DataRow

例外

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

解説

Contains メソッドを使用して、指定した値が行のキー列内に存在するかどうかを判断します。

使用例

[Visual Basic, C#, C++] DataRowCollection 内の各行の列 1 の値を出力する例を次に示します。

 
Private Sub PrintRows(myTable As DataTable)
    ' Print the first column for every row using the index.
    Dim i As Integer
    For i = 0 To myTable.Rows.Count - 1
        Console.WriteLine(myTable.Rows(i)(0))
    Next i
End Sub

[C#] 
private void PrintRows(DataTable myTable){
   // Print the CompanyName column for every row using the index.
   for(int i = 0; i < myTable.Rows.Count; i++){
      Console.WriteLine(myTable.Rows[i]["CompanyName"]);
   }
}

[C++] 
private:
 void PrintRows(DataTable* myTable){
    // Print the CompanyName column for every row using the index.
    for(int i = 0; i < myTable->Rows->Count; i++){
       Console::WriteLine(myTable->Rows->Item[i]->Item[S"CompanyName"]);
    }
 }

[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 ファミリ

参照

DataRowCollection クラス | DataRowCollection メンバ | System.Data 名前空間 | Contains