DataTable.Select Method

  • Thread starter Thread starter harry
  • Start date Start date
H

harry

Hi,

Can the DataTable.Select Method use 'Distinct' to remove duplicate rows? If
so how? I tried, however code triggered error 'no colmn 'Distinct' found'.

Thanks
Harry
 
No this is not possible using the Select method of the dataTable. You will
have to build in your functionality or ammend your query to return distinct
rows from the SQL server which is probable more sensible.

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .
If U Need My Email ,Ask Me

Time flies when you don't know what you're doing
 
Harry,

As Anushi wrote there is no standard distinct in Net 1.0 or 1.1

There is a sample in a page on MSDN, I find this sample I once made more
easy (and it is more complete)

\\\
Me.DataGrid1.DataSource = distinct(dt, "MyDistinctElement")
End Sub
Public Function distinct(ByVal dt As DataTable, _
ByVal dist As String) As DataTable
Dim dtclone As DataTable = dt.Clone
Dim dv As New DataView(dt)
dv.Sort = dist
Dim myselold As String = ""
For i As Integer = 0 To dv.Count - 1
If myselold <> dv(i)(dist).ToString Then
Dim drn As DataRow = dtclone.NewRow
For y As Integer = 0 To drn.ItemArray.Length - 1
drn(y) = dv(i)(y)
Next
myselold = dv(i)(dist).ToString
dtclone.Rows.Add(drn)
End If
Next
Return dtclone
End Function
///
I hope this helps?

Cor
 
AFAIK, I think the answer is no. This has four overloaded functions none of
which allow this, the filter is just that and has now way of knowing if it
has already displayed a row.


--

OHM ( Terry Burns )
. . . One-Handed-Man . . .
If U Need My Email ,Ask Me

Time flies when you don't know what you're doing
 
Back
Top