DataTable.Select distinct Method Query
DataTable.Select distinct Method Query
am 16.11.2007 04:12:00 von tvin
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
Re: DataTable.Select distinct Method Query
am 16.11.2007 10:56:35 von 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
Re: DataTable.Select distinct Method Query
am 16.11.2007 11:10:00 von tvin
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
>
>
>
Re: DataTable.Select distinct Method Query
am 16.11.2007 12:21:31 von Marc Gravell
With LINQ (.NET 3.5, C# 3), yes:
var distinctNames = (
from row in untypedDataTable.AsEnumerable()
select row.Field("Name")).Distinct();
foreach (var name in query) {
Console.WriteLine(name);
}
alternatively, if typed:
var distinctNames = (
from row in typedDataTable
select row.Name).Distinct();
Marc
Re: DataTable.Select distinct Method Query
am 17.11.2007 01:46:00 von tvin
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("Name")).Distinct();
>
> foreach (var name in query) {
> Console.WriteLine(name);
> }
>
> alternatively, if typed:
>
> var distinctNames = (
> from row in typedDataTable
> select row.Name).Distinct();
>
> Marc
>
>
>
Re: DataTable.Select distinct Method Query
am 17.11.2007 21:26:44 von 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