473,327 Members | 2,065 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,327 software developers and data experts.

DataTable.Select Method

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


Jul 21 '05 #1
5 8007
Hi Harry,

I don't believe distinct is supported. The only reserved words used in the
expression parser are:
And, Or, True, False, Is, In, Like, Not, Null, Between, Child, and Parent.
You'll have to code it by hand.
Here you go....

[HOW TO: Implement a DataSet SELECT DISTINCT Helper Class in Visual Basic
..NET]
http://support.microsoft.com/default...b;EN-US;325684

HTH,
Anushi (Grapecity)

"harry" <harry@nospam> wrote in message
news:eE**************@TK2MSFTNGP12.phx.gbl...
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

Jul 21 '05 #2
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" <harry@nospam> wrote in message
news:eE**************@TK2MSFTNGP12.phx.gbl...
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

Jul 21 '05 #3
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

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

Jul 21 '05 #4

Thanks everyone for your help.

Regards
Harry
"harry" <harry@nospam> wrote in message
news:eE**************@TK2MSFTNGP12.phx.gbl...
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

Jul 21 '05 #5
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

"harry" <harry@nospam> wrote in message
news:eE**************@TK2MSFTNGP12.phx.gbl...
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

Jul 21 '05 #6

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

Similar topics

8
by: Buddy | last post by:
Hello, We are using DataTable to store our data that we retrieve from SQL because it provides us with ROW/COLUMN concept. Due to DataTable been memory hungary we are finding that at least 40MB...
5
by: Stefan Turalski \(stic\) | last post by:
Hi, I'm wondering if there is a way to send a method parametrs by ref when DataTabel is a type of this value ? I done some sort of select over DataTable columns, just by removing them froma...
3
by: nandan | last post by:
Hi, Has any one ever compared the performance of calling a DataTable's Select method with a stored procedure doing the same thing? My point is: dataRows = DataTable.Select(filter) is better or...
2
by: JohnR | last post by:
Sorry if this is has an obvious answer, but I can't find it... I am using a datatable.select to obtain the rows in a datatable that meet certain criteria. My question is this: for each of the...
6
by: ronchese | last post by:
Hi. I'm trying to make a criteria string to use in Select() method of a datatable, searching for a date, but it is apparently not working! In one of my tests, I have a datatable with 1 row and...
4
by: Aryan | last post by:
Hi, I am having problem with DataTable.Select() method. I am using ASP.NET 2.0. I have DataSet which reads data from XML file using DataSet.ReadXML(). Now this dataset has various datatable,...
1
by: Maxwell2006 | last post by:
Hi, I am working with strongly typed datatables. What is the most efficient way to build a new DataTAble based on the result of DataTable.Select? At this point I use a foreach loop to do the...
13
by: =?Utf-8?B?UGV0ZXI=?= | last post by:
I want to create a new column in a datatable from two existing columns. I have no problem to create the new column using the datatable.columns.add method. The problem is the value of the new...
6
by: fniles | last post by:
I am using VB.NET 2005 and Access database. My program uses a timer that kicks in every 1 min to read from a database and copy the dataset table to a datatable. This database is in a class called...
3
by: Nuno Magalhaes | last post by:
Hello, I have a DataTable in which the items are of type MyClass. How can I use Select to compare a MyClass instance with the DataTable? Is there any overriden method (like the ToString()) to...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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...

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.