This documentation is archived and is not being maintained.

DataRowCollection.Item Property

Gets the row at the specified index.

[C#] In C#, this property is the indexer for the DataRowCollection class.

[Visual Basic]
Public Default ReadOnly Property Item( _
   ByVal index As Integer _
) As DataRow
[C#]
public DataRow this[
 int index
] {get;}
[C++]
public: __property DataRow* get_Item(
 int index
);
[JScript]
returnValue = DataRowCollectionObject.Item(index);
-or-
returnValue = DataRowCollectionObject(index);

[JScript] In JScript, you can use the default indexed properties defined by a type, but you cannot explicitly define your own. However, specifying the expando attribute on a class automatically provides a default indexed property whose type is Object and whose index type is String.

Arguments [JScript]

index
The zero-based index of the row to return.

Parameters [Visual Basic, C#, C++]

index
The zero-based index of the row to return.

Property Value

The specified DataRow.

Exceptions

Exception Type Condition
IndexOutOfRangeException The index value is greater than the number of items in the collection.

Remarks

Use the Contains method to determine if a given value exists in the key column of a row.

Example

[Visual Basic, C#, C++] The following example prints the value of column 1 of each row in a DataRowCollection.

[Visual Basic] 
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] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

DataRowCollection Class | DataRowCollection Members | System.Data Namespace | Contains

Show: