DataTable.Select distinct Method Query

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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
 
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
 
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
 
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
 
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
 
Back
Top