Hello, I need to select distinct rows from a dataset..
I have seen this posting:
http://www.computerhelp.forum/showthread.php?t=74539&highlight=distinct+dataview
http://support.microsoft.com/default.aspx?scid=kb;EN-US;325684
and
but this just seems like a long way of doing something that should be simple.. even the above code could be simplier... If i have to move through one dataset and create another.. couldnt I just do something like: dataset.Unique = True
Do youll have any suggestions?
thanks!
Lee
I have seen this posting:
http://www.computerhelp.forum/showthread.php?t=74539&highlight=distinct+dataview
http://support.microsoft.com/default.aspx?scid=kb;EN-US;325684
and
Code:
Public Function SelectDistinct(ByVal TableName As String, _
ByVal SourceTable As DataTable, _
ByVal FieldName As String) As DataTable
Dim dt As New DataTable(TableName)
dt.Columns.Add(FieldName, SourceTable.Columns(FieldName).DataType)
Dim dr As DataRow, LastValue As Object
For Each dr In SourceTable.Select("", FieldName)
If LastValue Is Nothing OrElse Not ColumnEqual(LastValue, dr(FieldName)) Then
LastValue = dr(FieldName)
dt.Rows.Add(New Object() {LastValue})
End If
Next
If Not ds Is Nothing Then ds.Tables.Add(dt)
Return dt
End Function
but this just seems like a long way of doing something that should be simple.. even the above code could be simplier... If i have to move through one dataset and create another.. couldnt I just do something like: dataset.Unique = True
Do youll have any suggestions?
thanks!
Lee