[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.sdk

How to perform "SELECT DISTINCT" with data tables

Spong

8/28/2002 10:38:00 PM

Is there any "quick" or "proper" way of doing a "SELECT DISTINCT colname" on
a DataTable?

Or do I have to loop through all the rows in the table and manually pick out
the distinct ones?

Thanks.


2 Answers

Per Hultqvist

8/29/2002 11:28:00 AM

0

Hi,

There is a Select-method on the DataTable-class but I don't believe it
handles DISTINCT (I could not find anything about it in the documentation).
Maybe you can find a solution using the Unique-property on the DataColumn or
use the UniqueConstraint-class, maybe in combination with GetErrors-method,
and some errorhandling too. Maybe merging the DataTable to a new DataTable
with the Unique-property=True on the unique column and ignoring the rows
that generates an error. But to be honest, looping through the DataRows,
might just be the "quick" and "proper" solution.

/Per Hultqvist

"Spong" <deSpong@hotmail.com> wrote in message
news:eRpmvKtTCHA.436@tkmsftngp10...
> Is there any "quick" or "proper" way of doing a "SELECT DISTINCT colname"
on
> a DataTable?
>
> Or do I have to loop through all the rows in the table and manually pick
out
> the distinct ones?
>
> Thanks.
>
>


colin

8/29/2002 12:55:00 PM

0

Ms seem to be suggesting that complex filters in ADO.net should be handled
with a hidden boolean column that is set true with a looping operation and
then filtered on using select or rowfilter. they seem to be acknowledging
problems with column expressions and bound datasets

personally I think select distinct is a missing feature

Colin

"Per Hultqvist" <per_hultqvist@hotmail.com> wrote in message
news:eiQQ26zTCHA.3016@tkmsftngp13...
> Hi,
>
> There is a Select-method on the DataTable-class but I don't believe it
> handles DISTINCT (I could not find anything about it in the
documentation).
> Maybe you can find a solution using the Unique-property on the DataColumn
or
> use the UniqueConstraint-class, maybe in combination with
GetErrors-method,
> and some errorhandling too. Maybe merging the DataTable to a new DataTable
> with the Unique-property=True on the unique column and ignoring the rows
> that generates an error. But to be honest, looping through the DataRows,
> might just be the "quick" and "proper" solution.
>
> /Per Hultqvist
>
> "Spong" <deSpong@hotmail.com> wrote in message
> news:eRpmvKtTCHA.436@tkmsftngp10...
> > Is there any "quick" or "proper" way of doing a "SELECT DISTINCT
colname"
> on
> > a DataTable?
> >
> > Or do I have to loop through all the rows in the table and manually pick
> out
> > the distinct ones?
> >
> > Thanks.
> >
> >
>
>