If you want to remove the duplicate records from a datatable then follow the below code:
VB.NET
Dim distinctTable As DataTable = dtRecords.DefaultView.ToTable(True, "ID", "Name", "Address")
Dim ht As New Hashtable
Dim DuplicateArrList As New ArrayList
For Each dr As DataRow In dtRecords.Rows
If (ht.Contains(dr(ColName))) Then
DuplicateArrList.Add(dr)
Else
ht.Add(dr(ColName), String.Empty)
End If
Next
For Each dr1 As DataRow In DuplicateArrList
dtRecords.Rows.Remove(dr1)
Next
Return dtRecords
Regards
Santosh
VB.NET
Dim distinctTable As DataTable = dtRecords.DefaultView.ToTable(True, "ID", "Name", "Address")
Dim ht As New Hashtable
Dim DuplicateArrList As New ArrayList
For Each dr As DataRow In dtRecords.Rows
If (ht.Contains(dr(ColName))) Then
DuplicateArrList.Add(dr)
Else
ht.Add(dr(ColName), String.Empty)
End If
Next
For Each dr1 As DataRow In DuplicateArrList
dtRecords.Rows.Remove(dr1)
Next
Return dtRecords
Regards
Santosh
No comments:
Post a Comment