473,545 Members | 2,688 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DataTable.Selec t Method

Hi,

Can the DataTable.Selec t 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 8028
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******** ******@TK2MSFTN GP12.phx.gbl...
Hi,

Can the DataTable.Selec t 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******** ******@TK2MSFTN GP12.phx.gbl...
Hi,

Can the DataTable.Selec t 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.Da taSource = distinct(dt, "MyDistinctElem ent")
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).ToS tring Then
Dim drn As DataRow = dtclone.NewRow
For y As Integer = 0 To drn.ItemArray.L ength - 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
///
I hope this helps?

Cor

Can the DataTable.Selec t 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******** ******@TK2MSFTN GP12.phx.gbl...
Hi,

Can the DataTable.Selec t 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******** ******@TK2MSFTN GP12.phx.gbl...
Hi,

Can the DataTable.Selec t 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
15256
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 of memory is been created every second which means the GC is concently running. We want to use something else that is not memory hungary and will...
5
10027
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 table is each of them isn't on a stirng, but right no I have to do it in a wat of: 1. passing DataTable to method (lets call it SelectOverDataTabel)...
3
5898
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 Passing paramters to stored procedure? The datatable holds about 500-700 rows at any given time. If I select one of the approaches the business...
2
8962
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 datarows that are returned to me as a result of the datatable.select how can I determine their index in the datatable.rows collection? For those...
6
4677
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 a field containing the following value (extracted from Immediate Window): ?dtbSample.Rows(0).Item("COM_STARTDATE") #5/8/2006 9:00:00 AM# {Date}...
4
7104
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, created by XML file. I am taking one of the datatable from this dataset and want to filter on that datatable using Select() method. Now here the...
1
5715
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 work manually. I am looking for an automated way. Thank you, Max
13
2582
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 column may become system.dbnull since one of the two existing columns may have system.dbnull. How can I fix it so the new column will get the value of...
6
3185
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 clsStat.vb. Then I pass this class to a thread. Each thread will call a function inside the clsStat.vb to do a "Select" of the datatable. Every...
3
2810
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 use it on Select? Thank you, Nuno Magalhães.
0
7499
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7432
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...
0
7943
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...
1
7456
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
1
5359
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5076
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...
0
3490
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...
0
3470
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1044
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.