Question: I have a DataTable that contains 4 rows. I want to compare a value in one column in row 1 with the value in row 2. Something similar to this:

```
For Each row As DataRow in drRows
  If row("column") <> row("column") 'I want the second row("column") to be the next row.
     'do something else
  End If
Next

```

Answer: 
You can always access a `DataRow` with its index ([`DataRowCollection.Item`](http://msdn.microsoft.com/en-us/library/system.data.datarowcollection.item.aspx)):

```
For i As Integer = 0 To tbl.Rows.Count - 1
    Dim row As DataRow = tbl.Rows(i)
    If i <> tbl.Rows.Count - 1 Then
        Dim nextRow As DataRow = tbl(i + 1)
        If row("column").Equals(nextRow("column")) Then
            'do something"
        End If
    End If
Next

```
You keep track of the last item:

```
Dim last As DataRow = Nothing

For Each row As DataRow In drRows
    If last IsNot Nothing Then
        ' Compare last with row
    End If

    last = row
Next

```