HighTechTalks DotNet Forums  

DataTable.Select distinct Method Query

Dotnet General Discussions microsoft.public.dotnet.general


Discuss DataTable.Select distinct Method Query in the Dotnet General Discussions forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
tvin
 
Posts: n/a

Default DataTable.Select distinct Method Query - 11-15-2007 , 10:12 PM






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

Reply With Quote
  #2  
Old   
Marc Gravell
 
Posts: n/a

Default Re: DataTable.Select distinct Method Query - 11-16-2007 , 04:56 AM






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



Reply With Quote
  #3  
Old   
tvin
 
Posts: n/a

Default Re: DataTable.Select distinct Method Query - 11-16-2007 , 05:10 AM



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:

Quote:
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




Reply With Quote
  #4  
Old   
Marc Gravell
 
Posts: n/a

Default Re: DataTable.Select distinct Method Query - 11-16-2007 , 06:21 AM



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



Reply With Quote
  #5  
Old   
tvin
 
Posts: n/a

Default Re: DataTable.Select distinct Method Query - 11-16-2007 , 07:46 PM



Hi Marc

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

thanks

Tvin

"Marc Gravell" wrote:

Quote:
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




Reply With Quote
  #6  
Old   
Marc Gravell
 
Posts: n/a

Default Re: DataTable.Select distinct Method Query - 11-17-2007 , 03:26 PM



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

Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.