Distinct datatable 1.0


/ Published in: VB.NET
Save to your folder(s)



Copy this code and paste it in your HTML
  1. Public Function DistinctRows_Int32_Key(ByVal dt As DataTable, ByVal keyfield As String) As DataTable
  2. Dim newTable As DataTable = dt.Clone
  3. Dim keyval As Int32 = 0
  4. Dim dv As DataView = dt.DefaultView
  5.  
  6. dv.Sort = keyfield
  7. If dt.Rows.Count > 0 Then
  8. For Each drv As DataRowView In dv '.ToTable.Rows
  9. If drv("mark") <> "PG" Then
  10. newTable.ImportRow(drv.Row)
  11. ElseIf Not drv.Item(keyfield) = keyval Then
  12. newTable.ImportRow(drv.Row)
  13. keyval = drv.Item(keyfield)
  14. End If
  15. Next
  16. Else
  17. newTable = dt.Clone
  18. End If
  19. Return newTable
  20. End Function

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.