DataTable.Select distinct Method Query

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
 
M

Marc Gravell

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
 
G

Guest

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
 
M

Marc Gravell

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
 
M

Marc Gravell

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top