Hi;

I am trying to do some calc for a DataTable populated from database. The
DataTable has composite key e.g.ID, Date.

My question is:

What is the best and effective way to get the distinct list of ID
from DataTable just like SQL "select distinct ID from table"?


Thank you for your help!

Yi

Re: How to get distinct list of a column from a DataTable by Val

Val
Mon Aug 16 21:00:24 CDT 2004

Hi,

If you need to get just a list of unique IDs, then what you could do is to
create DataView sorted using ID and then loop through the records to compare
previous and current value for ID. It will work pretty fast. If you need to
get a DataTable with distinct records, then you could use a helper class as
described in next KB

http://support.microsoft.com/default.aspx?scid=kb;en-us;325684&Product=adonet

--
Val Mazur
Microsoft MVP


"Yi Jiang" <y.jiang@sympatico.ca> wrote in message
news:ztcUc.9927$Tr.526507@news20.bellglobal.com...
> Hi;
>
> I am trying to do some calc for a DataTable populated from database. The
> DataTable has composite key e.g.ID, Date.
>
> My question is:
>
> What is the best and effective way to get the distinct list of ID
> from DataTable just like SQL "select distinct ID from table"?
>
>
> Thank you for your help!
>
> Yi
>
>



Re: How to get distinct list of a column from a DataTable by Yi

Yi
Wed Aug 18 18:24:47 CDT 2004

Thank you very much!


"Val Mazur" <group51a@hotmail.com> wrote in message
news:OieQ53$gEHA.3236@TK2MSFTNGP10.phx.gbl...
> Hi,
>
> If you need to get just a list of unique IDs, then what you could do is to
> create DataView sorted using ID and then loop through the records to
compare
> previous and current value for ID. It will work pretty fast. If you need
to
> get a DataTable with distinct records, then you could use a helper class
as
> described in next KB
>
>
http://support.microsoft.com/default.aspx?scid=kb;en-us;325684&Product=adonet
>
> --
> Val Mazur
> Microsoft MVP
>
>
> "Yi Jiang" <y.jiang@sympatico.ca> wrote in message
> news:ztcUc.9927$Tr.526507@news20.bellglobal.com...
> > Hi;
> >
> > I am trying to do some calc for a DataTable populated from database.
The
> > DataTable has composite key e.g.ID, Date.
> >
> > My question is:
> >
> > What is the best and effective way to get the distinct list of ID
> > from DataTable just like SQL "select distinct ID from table"?
> >
> >
> > Thank you for your help!
> >
> > Yi
> >
> >
>
>