How do I select distinct rows from a DataTable?

J

Jim H

I am storing incoming data in memory using a DataTable. After I'm done
retrieving the data I need to get the distinct rows. I tried using
DataTable.Select but that doesn't work.

If I have columns "col1", "col2", "col3" in my DataTable "Table1", I need to
basically be able to do this:
select distinct col2 form Table1

I tried doing this:
DataRow[] ResultsRowArray = MyTable.Select("distinct col2");

This obviously does not work. How can I get back an array of distinct rows?
I don't care if it all 3 columns or just that one.

BTW I am not connected to any databases. I don't need to store the data
like that permanently.

Thanks,
jim
 
V

Vagabond Software

Jim H said:
I am storing incoming data in memory using a DataTable. After I'm done
retrieving the data I need to get the distinct rows. I tried using
DataTable.Select but that doesn't work.

If I have columns "col1", "col2", "col3" in my DataTable "Table1", I need to
basically be able to do this:
select distinct col2 form Table1

I tried doing this:
DataRow[] ResultsRowArray = MyTable.Select("distinct col2");

I don't believe the DataTable Select method supports the DISTINCT keyword in any current version. It appears you may have to code it yourself.

The following Microsoft link has another link to something called the SelectDistinct method. You could use this in your own derived DataTable class or just add it to on of your existing assemblies.

http://support.microsoft.com/default.aspx?scid=kb;en-us;326176#1

- carl
 
J

Jim H

That's what I thought.
Thanks,
jim

Jim H said:
I am storing incoming data in memory using a DataTable. After I'm done
retrieving the data I need to get the distinct rows. I tried using
DataTable.Select but that doesn't work.

If I have columns "col1", "col2", "col3" in my DataTable "Table1", I need to
basically be able to do this:
select distinct col2 form Table1

I tried doing this:
DataRow[] ResultsRowArray = MyTable.Select("distinct col2");

I don't believe the DataTable Select method supports the DISTINCT keyword in
any current version. It appears you may have to code it yourself.

The following Microsoft link has another link to something called the
SelectDistinct method. You could use this in your own derived DataTable
class or just add it to on of your existing assemblies.

http://support.microsoft.com/default.aspx?scid=kb;en-us;326176#1

- carl
 

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