473,395 Members | 1,488 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Filtering a dataset

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
Nov 20 '05 #1
3 927
sorted

found this article
http://support.microsoft.com/?kbid=325684
"Craig G" <Ga*******@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
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

Nov 20 '05 #2
There is no direct way to do this, but I think this may well help you.

http://www.dotnet247.com/247referenc...ck_325684.aspx

--

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

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

"Craig G" <Ga*******@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
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

Nov 20 '05 #3
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
///
Nov 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Alex Ayzin | last post by:
Hi, I have a problem that might be easy to solve(possibly, I've just overlooked an easy solution). Here we go: I have a dataset with 2 datatables in it. Now, I need to do the following: if...
3
by: serge calderara | last post by:
Dear all, I have a csv file data which has been read and populate on a dataset object. then I need to bind part of the content of the dataset to a treeview control. I have read that XML format...
0
by: Patrick | last post by:
I'm working on a contact management application, and need a hand with one aspect... Here's what I want to create: ------------------------------------ A form split into two parts. There is a...
0
by: Jenny C. | last post by:
Hi I am trying to do a SUM on a DataSet column with the following code // ds is the DataSet that I need to calculate data fro String filter2 = "EmpNo = " + this.EmpNo + " AND WEEK_ENDING >= '"...
2
by: Marco Ippolito | last post by:
I have an offline DataSet: id (PK, sorted ASC), firstname, enabled 1, Aaron, true 2, Bill, false 3, Charlie, true .... 10001, Mike, false 10002, Nathan, false
0
by: ber.janssens | last post by:
Hi, I am trying the new ObjectDataSource from ASP.NET 2.0. I connected a Gridview with ObjectDataSource which is connected to a webservice which returns a DataSet. In the Webmethod I return...
7
by: | last post by:
Hello, Does anyone have an idea on how I can filter the data in the gridview control that was returned by an sql query? I have a gridview that works fine when I populate it with data. Now I...
5
by: LDD | last post by:
Hi Folks I'm trying to determine a way to handle paging, filtering and sorting in a datagrid. If I choose to filter and sort, I'd like to return a subset. If that resultset has more records...
2
by: Jason Huang | last post by:
Hi, I use the ReadXML method in my C# Windows Form project. Here is some of my C# code: xmlDS.ReadXml(curDir + "\\Dept.xml") ; There're 20 rows and 5 columns in the Dept.xml. But now I just...
3
by: Shawn Ramirez | last post by:
As with most web applications speed is a huge deal to me in my applications. My customers don't really care if my app is a true 3 tier application or not, they just want it to be faster then it was...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.