Filtering a dataset

2 views
Skip to first unread message

Craig G

unread,
Jul 6, 2004, 5:57:16 AM7/6/04
to
at the moment i have a dataset that returns data

but i want to be able to filter the data so that there is only one occurence
of each item (i.e. DISTINCT)

the original dataset is populated by a stored_proc. i cant put distinct in
the stored_proc as it is a SQL2000 system_stored_proc

i was going to filter by using RowFilter method on a Dataview but cant use
DISTINCT

how can i do this?

Cheers,
Craig


Craig G

unread,
Jul 6, 2004, 6:34:36 AM7/6/04
to
sorted

found this article
http://support.microsoft.com/?kbid=325684


"Craig G" <Gamb...@hotmail.com> wrote in message
news:%230UIG$zYEHA...@TK2MSFTNGP09.phx.gbl...

One Handed Man ( OHM - Terry Burns )

unread,
Jul 6, 2004, 6:42:07 AM7/6/04
to
There is no direct way to do this, but I think this may well help you.

http://www.dotnet247.com/247reference/a.aspx?u=http://www.kbalertz.com/Feedback_325684.aspx

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .

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

"Craig G" <Gamb...@hotmail.com> wrote in message
news:%230UIG$zYEHA...@TK2MSFTNGP09.phx.gbl...

Cor Ligthert

unread,
Jul 6, 2004, 8:30:03 AM7/6/04
to
Hi Craig,

Before I knew there was a sample one on MSDN I made this one.

It uses the dataview and is therefore probably a little bit faster, you can
use it with option Strict On, it returns back whole rows of data and in my
opinion it is much simpler to use.

Maybe you can try it, it was just a try and I tried it now again, and it did
work?

Cor

\\\
Me.DataGrid1.DataSource = mydistinct.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
///


Reply all
Reply to author
Forward
0 new messages