Return to Snippet

Revision: 53039
at November 10, 2011 22:19 by Gompje


Initial Code
Public Function DistinctRows_Int32_Key(ByVal dt As DataTable, ByVal keyfield As String) As DataTable
            Dim newTable As DataTable = dt.Clone
            Dim keyval As Int32 = 0
            Dim dv As DataView = dt.DefaultView

            dv.Sort = keyfield
            If dt.Rows.Count > 0 Then
                For Each drv As DataRowView In dv '.ToTable.Rows
                    If drv("mark") <> "PG" Then
                        newTable.ImportRow(drv.Row)
                    ElseIf Not drv.Item(keyfield) = keyval Then
                        newTable.ImportRow(drv.Row)
                        keyval = drv.Item(keyfield)
                    End If
                Next
            Else
                newTable = dt.Clone
            End If
            Return newTable
        End Function

Initial URL


Initial Description


Initial Title
Distinct datatable 1.0

Initial Tags
Net

Initial Language
VB.NET