Can someone tell me what I may be doing wrong here...
I'm trying to remove rows from a table in a dataset that have the same data.
My code is pasted below.
The 2nd time it runs through the code, I get an error message "Deleted row
information cannot be accessed through the row" on the line 'drT2 =
ds.Tables(0).Rows(varI + 1)
'
How can I fix this??
Public Function removeDuplicateRowsDS(ByVal ds As DataSet, ByVal
strFieldName As String) As DataSet
'Removes duplicate rows from a dataset
Dim varI As Integer
Dim strTemp As String
Dim strTemp2 As String
Dim drT As DataRow
Dim drT2 As DataRow
Do While varI < (ds.Tables(0).Rows.Count) - 1
drT = ds.Tables(0).Rows(varI)
strTemp = drT(strFieldName).ToString
drT2 = ds.Tables(0).Rows(varI + 1)
strTemp2 = drT2(strFieldName).ToString
If strTemp = strTemp2 Then
ds.Tables(0).Rows(varI).Delete()
Else
varI = varI + 1
End If
Loop
Return ds
End Function
TIA
Amber