473,385 Members | 1,356 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,385 software developers and data experts.

Dataview, Dataset - Select Distinct

I don't understand why the dataview or the dataset does not have a 'Select Distinct' option. They both can do so much to filter the data except that. The article Microsoft has 326176 works, but not if you need to select distinct on multiple fields.

Does anyone have any suggestions

Thanks
Diann

Jul 21 '05 #1
6 10872
Dianna:

What is the SQL Equivalent that you are thinking of writing? If you are
trying return distinct values of the combination of say two columns for
instance, you can do a sort by the first field then the secondand then just
walk through it from there. Agreed it's not elegant but a datatable isn't
a full featured RDBMS system. They are pretty darned powerful so I know
it's easy to expect such things, but if you need some really complex
filtering, you may just want to make a trip to the DB with a DataReader.

HTH,

Bill
"Dianna" <an*******@discussions.microsoft.com> wrote in message
news:3A**********************************@microsof t.com...
I don't understand why the dataview or the dataset does not have a 'Select Distinct' option. They both can do so much to filter the data except that.
The article Microsoft has 326176 works, but not if you need to select
distinct on multiple fields.
Does anyone have any suggestions?

Thanks,
Dianna

Jul 21 '05 #2
Might I ask how that would look

dt.Columns.Add(FieldName1, SourceTable.Columns(FieldName1).DataType
dt.Columns.Add(FieldName2, SourceTable.Columns(FieldName2).DataType
dt.Columns.Add(FieldName3, SourceTable.Columns(FieldName3).DataType
dt.Columns.Add(FieldName4, SourceTable.Columns(FieldName4).DataType

Dim dr As DataRow, LastValue As Objec
For Each dr In SourceTable.Select("", FieldName1
If LastValue Is Nothing OrElse Not ColumnEqual(LastValue, dr(FieldName1)) The
LastValue = dr(FieldName1
dt.Rows.Add(New Object() {LastValue}
End I
Nex

If Not ds Is Nothing Then ds.Tables.Add(dt

'call to function
dsHelper.SelectDistinct("DistinctShows", ds.Tables!ShowNo, "show_name", "dow", "start_time", "end_time"

I'm wondering if it might be easier to just sort the table and just write an old fashion control break. It might be more elegant
Thanks
Diann
Jul 21 '05 #3
Cor
Hi Dianna,
I'm wondering if it might be easier to just sort the table and just write

an old fashion control >break. It might be more elegant.
I got this idea from your sentence, it is quick made, but I think that it is
generic usable.

I hope this helps a little bit?

Cor
\\\
Me.DataGrid1.DataSource = mydistinct.distinct(dt, "elem1")
///
\\\
Public Class Selectclass
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 dv.Count - 1
drn(y) = dv(i)(y)
Next
myselold = dv(i)(dist).ToString
dtclone.Rows.Add(drn)
End If
Next
Return dtclone
End Function
End Class
///
Jul 21 '05 #4
Hi Cor

Thats sort of what I did (kind of had no choice).

I am sure in the future their will be a 'Select Distict' for the tables.

Thanks
Diann

Jul 21 '05 #5
Cor
Hi Dianna,
I'm wondering if it might be easier to just sort the table and just write

an old fashion control >break. It might be more elegant.
I got this idea from your sentence, it is quick made, but I think that it is
generic usable.

I hope this helps a little bit?

Cor
\\\
Me.DataGrid1.DataSource = mydistinct.distinct(dt, "elem1")
///
\\\
Public Class Selectclass
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 dv.Count - 1
drn(y) = dv(i)(y)
Next
myselold = dv(i)(dist).ToString
dtclone.Rows.Add(drn)
End If
Next
Return dtclone
End Function
End Class
///
Nov 22 '05 #6
Hi Cor

Thats sort of what I did (kind of had no choice).

I am sure in the future their will be a 'Select Distict' for the tables.

Thanks
Diann

Nov 22 '05 #7

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

Similar topics

7
by: Joe | last post by:
Not sure what group this question is better suited for so I sent it to both. I have a DataTable which contains 1545 rows. I have a method that returns a DataTable of distinct rows based on one...
36
by: kjvt | last post by:
Based on a prior posting, I've written a function to convert a recordset to a dataview. The first call to the function for a given recordset works perfectly, but the second call always returns a...
13
by: Steve | last post by:
I have a form with a dataset and a datagrid. I created a dataview on this dataset. When the user modifies the datagrid, I look up this record in the dataview to make sure it is unique. Here is...
11
by: Tim Frawley | last post by:
I need to return a DataRow or the Row Index in a DataSet wherein the value I am attempting to find is not a primary key. I have to do this often, more than 200 times when importing a file so it...
5
by: David Wender | last post by:
I want to create a dataview with a sort on multiple columns. However, when I use FindRows, I only want to search some of the columns, not all. Is this possible? I have not been able to make it...
8
by: Jason L James | last post by:
Hi all, does anyone know if I can create a dataview from multiple datatables. My dataset is constructed from four separate tables and then the relationships are added that link the tables...
17
by: A_PK | last post by:
I have problem databinding the DataGrid with DataView/DataSet after the filter... I create the following proceudre in order for user to filter as many as they want, but the following code is only...
3
by: Li Pang | last post by:
Hi, I want to know how to create a dataview from a datatable of DISTINCT data. Thank in advance
2
by: =?Utf-8?B?cmFuZHkxMjAw?= | last post by:
I have the following line of code (.NET 2.0): myDataView.RowFilter = "SELECT DISTINCT CYCLE_DATE"; where CYCLE_DATE is one of my column names. This throws the following exception: Syntax...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...

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.