Sub SetDuplicateFlag(ByRef dt As DataTable, ByVal DupColName As String)
Dim ssort As String = ""
Dim col As DataColumn
Dim scol As DataColumn
For Each scol In dt.Columns
If scol.ColumnName = DupColName Then Continue For
If ssort <> "" Then ssort &= ","
ssort &= scol.ColumnName
Next
dt.DefaultView.Sort = ssort
Dim i As Integer, bEquals As Boolean, c As Integer, ccount As Integer
ccount = dt.Columns.Count
For i = dt.Rows.Count - 1 To 0 Step -1
bEquals = True
For c = 0 To ccount - 1
If dt.Columns(c).ColumnName = DupColName Then Continue For
If Not i = 0 Then
If dt.DefaultView(i)(c).ToString() <> dt.DefaultView(i - 1)(c).ToString() Then
bEquals = False
Exit For
End If
Else
bEquals = False
End If
Next c
If bEquals Then
dt.DefaultView(i - 1).Item(DupColName) = True
dt.DefaultView(i).Item(DupColName) = True '(i).Delete()
Else
If dt.DefaultView(i).Item(DupColName) <> True Then
dt.DefaultView(i).Item(DupColName) = False
End If
End If
Next
End Sub
|