1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| Private Function SelectDistinct(ByVal table As DataTable, ByVal champ As String) As DataTable
Dim i As Int32
Dim ret As Int16
Dim dtResultat As New DataTable
dtResultat.Columns.Add(champ, table.Columns(champ).DataType)
dtResultat.DefaultView.Sort = champ
dtResultat.DefaultView.ApplyDefaultSort = True
For i = 0 To table.Rows.Count - 1
If dtResultat.Rows.Count > 0 Then
ret = dtResultat.DefaultView.Find(table.Rows(i)(champ))
If ret = -1 Then
dtResultat.Rows.Add(dtResultat.NewRow)
dtResultat.Rows(dtResultat.Rows.Count - 1)(champ) = table.Rows(i)(champ)
End If
Else
dtResultat.Rows.Add(dtResultat.NewRow)
dtResultat.Rows(0)(champ) = table.Rows(0)(champ)
End If
Next
Return dtResultat
End Function |
Partager