By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,573 Members | 1,924 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,573 IT Pros & Developers. It's quick & easy.

datatable unique rows

P: n/a
Hello Group,
I have a datatable with duplicate values in a column and I
need to get distinct rows ordered by <col name>. How do I go abt it without
hitting the db?

Thanks for ur help,
Chris.
Nov 21 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Hi Chris,

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that you need to get distinct rows from a
column with duplicate values and sort it. If there is any misunderstanding,
please feel free to let me know.

As far as I know, there doesn't seem to be a function or an expression for
us to get distinct rows directly from the column. I think we have to go
through each row and get data then compare with existing data to see if it
is duplicated.

However, we can also use some tricks to simplify the compare progress. For
example, we can create a DataTable with a single column. We set a unique
contraint on that column. And then copy data of the original column one by
one to the new column. When duplicate data is copied, an exception will be
thrown. We just swallow that exception and continue. Then we'll get a
column distinct data.

HTH.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Nov 21 '05 #2

P: n/a
Sounds good!!

Thanks,
Chris.

"Kevin Yu [MSFT]" <v-****@online.microsoft.com> wrote in message
news:ys*************@cpmsftngxa06.phx.gbl...
Hi Chris,

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that you need to get distinct rows from a
column with duplicate values and sort it. If there is any misunderstanding, please feel free to let me know.

As far as I know, there doesn't seem to be a function or an expression for
us to get distinct rows directly from the column. I think we have to go
through each row and get data then compare with existing data to see if it
is duplicated.

However, we can also use some tricks to simplify the compare progress. For
example, we can create a DataTable with a single column. We set a unique
contraint on that column. And then copy data of the original column one by
one to the new column. When duplicate data is copied, an exception will be
thrown. We just swallow that exception and continue. Then we'll get a
column distinct data.

HTH.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Nov 21 '05 #3

P: n/a
Hi Chris,

Thanks for sharing your experience with all the people here. If you have
any questions, please feel free to post them in the community.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Nov 21 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.