Dim CurrentRow As DataRow
Dim NextRow As DataRow
For i = 0 To dt.Rows.Count - 1
'checks if taskid matches row id. if so then enter condition
If dt.Rows(i)("TaskID") = RowID Then
'needs to check if next row exist. if it does then get the next row . if not (hence its the final row get it)
If dt.Rows(i + 1) Is Nothing Then
CurrentRow = dt.Rows(i)
Else
NextRow = dt.Rows(i + 1)
End If
Exit For
End If
Next
I've literally swiped the internet and yet cannot find a valid solution. I'm looping through this datatable and I'm retrieving the next row. But always no matter what i do a point will come where the dt.rows(i+1) will no longer proceed as it cannot find any rows in that position. One thing i don't understand is that if dt.rows(i+1) comes back empty or does not exist as the error suggests then you could do a simple if condition to check if its nothing. But I get this enter image description here