Hi everybody,
I have 2 datatables in my ASP.NET application. I loop though both of them, and if I find a match, I delete that particular row from the outer datatable, lik so:
For i As Integer = 0 To dtFixedActs.Count - 1
For j As Integer = 0 To dtTotals.Count - 1
If dtFixedActs.Rows(i).Item("Activity") = dtTotals.Rows(j).Item("Activity") Then
dtFixedActs.Rows(i).Delete()
i += 1
j += 1
End If
Next
dtFixedActs.AcceptChanges()
Next
This works fine, except when the dtFixedActs contains only 1 row and a match is found in the other datatable. I get an "there is no row at position 1" error. This makes sense because with i+=1 I want to get to the next row, which is not possible in this case.
I have tried to move around the dtFixedActs.AcceptChanges command in and out of the 1st loop but to no avail. I also commented out the i+=1 line, but then I get the "Deleted row information cannot be accessed through the row." error.
I don't know how to program around this issue. When dtFixedActs contains more than 1 row, the problem does not occur.
Any suggestions? Thanks in advance!