ExtensionMethod.NET Home of 880 C#, Visual Basic, F# and Javascript extension methods

RemoveDuplicateRows

This extension method will remove duplicate rows from the DataTable that it is called from.

Source

''' <summary>
''' Removes duplicates from the data table.
''' </summary>
''' <param name="dt"></param>
''' <remarks>
''' This extension method will remove duplicate rows from the DataTable that it is called from.
''' </remarks>
<Extension()> _
Public Sub RemoveDuplicateRows(ByRef dt As DataTable)

    Dim columnList(dt.Columns.Count - 1) As String
    For counter As Integer = 0 To dt.Columns.Count - 1
        columnList(counter) = dt.Columns(counter).ColumnName
    Next
    dt = dt.DefaultView.ToTable(True, columnList)
End Sub

Example

dt.RemoveDuplicateRows()

Author: Me

Submitted on: 8 mrt. 2010

Language: VB

Type: System.Data.DataTable

Views: 4655