473,769 Members | 3,823 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 10897
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*******@disc ussions.microso ft.com> wrote in message
news:3A******** *************** ***********@mic rosoft.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.Col umns(FieldName1 ).DataType
dt.Columns.Add( FieldName2, SourceTable.Col umns(FieldName2 ).DataType
dt.Columns.Add( FieldName3, SourceTable.Col umns(FieldName3 ).DataType
dt.Columns.Add( FieldName4, SourceTable.Col umns(FieldName4 ).DataType

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

If Not ds Is Nothing Then ds.Tables.Add(d t

'call to function
dsHelper.Select Distinct("Disti nctShows", ds.Tables!ShowN o, "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.Da taSource = mydistinct.dist inct(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).ToS tring 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).ToS tring
dtclone.Rows.Ad d(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.Da taSource = mydistinct.dist inct(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).ToS tring 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).ToS tring
dtclone.Rows.Ad d(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
9148
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 column. This table ends up with 386 rows. I need to loop through the smaller table and filter a DataView based on each row from this table. This loops takes ~5 secs. Is there anyway to improve this?
36
4483
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 dataview with a count = 0. Can someone explain why and how I might work around this problem? Here is the code for my function: Public Shared Function GetViewFromRS(ByVal pRS As ADODB.Recordset) _ As DataView
13
2116
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 the confusion......... I thought that the DataView is the view from the dataset, but it seems that the dataview has the records that are in the datagrid, because everytime I search for a record that I know is NOT in the dataset, it finds it. I...
11
27436
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 needs to be fast. Could I use a Dataview to filter for the value (which is unique) and return either the DataRow object so I can modify it and put it back into the DataSet the view is based on or somehow get the RowIndex in the DataSet that the...
5
8834
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 happen. Dim objKeys(2) as Object objKeys(0) = "CL" objKeys(2) = 4000 Dim posView As DataView = New DataView(posDS.Tables("Positions"), _
8
10417
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 together. To make data entry easier I would like to combine selected columns from the four tables onto a single dataview that could be used as the datasource for a datagrid control. The distinct updates, insert ans delete
17
2770
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 allow user to filter the first time, when they tried the second time, the speficied cast error message will prompt one.... I create a mydataset1 first, and the mydataset1 data source was getting from DataGrid.DataSource.
3
4370
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
18967
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 error: Missing operand after 'DISTINCT' operator. Any suggestions on what this is really trying to tell me?
0
9420
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10205
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10035
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9851
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8863
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6662
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5293
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3556
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2811
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.