473,396 Members | 1,898 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,396 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


Nov 21 '05 #1
5 6160
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

Nov 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

Nov 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

Nov 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

Nov 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

Nov 21 '05 #6

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

Similar topics

2
by: doug | last post by:
I would like to do a select distinct on a fieldname in a dataset. Is this possible using the DataTable.Select Method? If so do you have an example? I can use the method to do things like...
5
by: harry | last post by:
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
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: Derrick | last post by:
or is there some other MaxRows type of prop so you can limit result set? Thanks in advance! Derrick
1
by: Joe Smith | last post by:
Hello, Can we do SQL style SELECT queries in the DataTable.Select Method. e.g Filter String Expression = id < 5 AND (age <20 OR age >50) My goal is to be able to do advanced queries on a...
0
by: Vagabond Software | last post by:
I posted this problem earlier and now have more information. I use the DataTable Select method to get find the most recent "LastModified" date in a table of similarly named files. I then use the...
3
by: emailtonitin | last post by:
Hi, I am having a problem with the default sorting mechanism employed by the datatable.select method - I have a datatable having rows (simplified for clarity) - name ----- c a
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...
1
by: =?Utf-8?B?d2VzdGNvYXN0Y29kZQ==?= | last post by:
void CreateBatches(string currDir, DataTable hvTable) { string id; DirectoryInfo di = new DirectoryInfo(currDir); StreamWriter writer = new StreamWriter(currDir + "\\Index.dat", false); DataRow...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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
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...
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.