473,480 Members | 1,873 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

DataTable.Select distinct Method Query

Hi everybody
i have a datatable, i want to select distinct value from datatable and not
database.
so is there any method that can provide this query:
Select DISTINCT from DataTable
please help me
thanks
Tvin
Nov 16 '07 #1
5 26595
Can you clarify the question? I'm not 100% sure I have followed it...

However, looking forward a few weeks, LINQ supports this via
Distinct() [which can accept a comparer], and .NET 3.5 ships with LINQ
extensions for DataTable etc.

I may not have fully followed the question, though.

Marc
Nov 16 '07 #2
Hi Marc thanks for your reply
i fill datatable from database, after that i don't want to use the database
again to select the same information but with different Query like: select
distinct field ...

so i want to know if there is select distinct method for datatable.

thanks
"Marc Gravell" wrote:
Can you clarify the question? I'm not 100% sure I have followed it...

However, looking forward a few weeks, LINQ supports this via
Distinct() [which can accept a comparer], and .NET 3.5 ships with LINQ
extensions for DataTable etc.

I may not have fully followed the question, though.

Marc
Nov 16 '07 #3
With LINQ (.NET 3.5, C# 3), yes:

var distinctNames = (
from row in untypedDataTable.AsEnumerable()
select row.Field<string>("Name")).Distinct();

foreach (var name in query) {
Console.WriteLine(name);
}

alternatively, if typed:

var distinctNames = (
from row in typedDataTable
select row.Name).Distinct();

Marc
Nov 16 '07 #4
Hi Marc

do you think i can use this LINQ idea with vb.net ?

thanks

Tvin

"Marc Gravell" wrote:
With LINQ (.NET 3.5, C# 3), yes:

var distinctNames = (
from row in untypedDataTable.AsEnumerable()
select row.Field<string>("Name")).Distinct();

foreach (var name in query) {
Console.WriteLine(name);
}

alternatively, if typed:

var distinctNames = (
from row in typedDataTable
select row.Name).Distinct();

Marc
Nov 17 '07 #5
I know that the answer is yes, but I don't know enough VB to prove
it ;-p

Either way, you'll need to wait a few weeks for .NET 3.5 to be
released.

Marc
Nov 17 '07 #6

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

Similar topics

2
2228
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
8016
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
6422
by: Tcs | last post by:
My backend is DB2 on our AS/400. While I do HAVE DB2 PE for my PC, I haven't loaded it yet. I'm still using MS Access. And no, I don't believe this is an Access question. (But who knows? I...
8
15253
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...
2
55854
by: Michael Howes | last post by:
I have a single DataTable in a DataSet. It has 4 columns and i'd like to get a handful of counts of unique items in 3 of the 4 columns. Can a DataTables Select or Compute methods to COUNT DISTINCT?...
2
100335
by: Jim H | last post by:
I am storing incoming data in memory using a DataTable. After I'm done retrieving the data I need to get the distinct rows. I tried using DataTable.Select but that doesn't work. If I have...
10
6497
by: dauphian | last post by:
Hello, I am new to .net and am trying to build a report application that queries 4 different tables based on a id, and I need to return them in the same table for easy viewing. Basically, I...
2
13437
by: Rich | last post by:
Hello, I am just checking if there is a property or technique for displaying or retrieving from a dataTable the top 1 row(s) for rows containing duplicate keys (IDs). I have to pull data from a...
6
3180
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...
0
7041
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
6908
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
7043
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
7081
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...
1
6737
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
2995
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...
0
2984
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
563
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
179
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...

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.