PC Review


Reply
Thread Tools Rating: Thread Rating: 4 votes, 5.00 average.

Re: DataTable.Compute or .Select to count distinct values in a column

 
 
Miha Markic [MVP C#]
Guest
Posts: n/a
 
      27th Aug 2004
Hi,

I would go with a simple foreach (DataRow row in table.Rows) loop.

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
miha at rthand com
www.rthand.com

"M K" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>I have a Datatable in a DataSet that for one part of the process I need to
> know the count of DISTINCT/UNIQUE values in one column. How can I achieve
> this.



 
Reply With Quote
 
 
 
 
Sasidhar
Guest
Posts: n/a
 
      27th Aug 2004
Miha,
May be I am not getting you. How can you do that using a foreach? Can you
please explain.

MK,
Look at this article. You can utilise it to find out the count.
http://support.microsoft.com/default...b;EN-US;326176

Or if the number of rows is less then you can use a for loop and a
hashtable. As you loop insert into hashtable. If you find a duplicate ignore
the key. At the end you can just get the count from hashtable.

-SP

"Miha Markic [MVP C#]" <miha at rthand com> wrote in message
news:(E-Mail Removed)...
> Hi,
>
> I would go with a simple foreach (DataRow row in table.Rows) loop.
>
> --
> Miha Markic [MVP C#] - RightHand .NET consulting & development
> miha at rthand com
> www.rthand.com
>
> "M K" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> >I have a Datatable in a DataSet that for one part of the process I need

to
> > know the count of DISTINCT/UNIQUE values in one column. How can I

achieve
> > this.

>
>



 
Reply With Quote
 
 
 
 
Miha Markic [MVP C#]
Guest
Posts: n/a
 
      27th Aug 2004
Hi,

"Sasidhar" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Miha,
> May be I am not getting you. How can you do that using a foreach? Can you
> please explain.


Well, yes, doing it manually was what i was thinking.
Storing unique value and its count (if you want to count the key occurences
also) in a hashtable is a good one.

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
miha at rthand com
www.rthand.com

> MK,
> Look at this article. You can utilise it to find out the count.
> http://support.microsoft.com/default...b;EN-US;326176
>
> Or if the number of rows is less then you can use a for loop and a
> hashtable. As you loop insert into hashtable. If you find a duplicate
> ignore
> the key. At the end you can just get the count from hashtable.
>
> -SP
>
> "Miha Markic [MVP C#]" <miha at rthand com> wrote in message
> news:(E-Mail Removed)...
>> Hi,
>>
>> I would go with a simple foreach (DataRow row in table.Rows) loop.
>>
>> --
>> Miha Markic [MVP C#] - RightHand .NET consulting & development
>> miha at rthand com
>> www.rthand.com
>>
>> "M K" <(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed)...
>> >I have a Datatable in a DataSet that for one part of the process I need

> to
>> > know the count of DISTINCT/UNIQUE values in one column. How can I

> achieve
>> > this.

>>
>>

>
>



 
Reply With Quote
 
=?Utf-8?B?TSBL?=
Guest
Posts: n/a
 
      30th Aug 2004
What I would want is a count of how many different values there are. I could
dump to a hash table, then get the .length. Seems costly...
 
Reply With Quote
 
Steven Cheng[MSFT]
Guest
Posts: n/a
 
      31st Aug 2004
Hi Mark,

The .net framework's DataTable's select method only provide some very basic
semantics, which haven't include the "unique item count" function, you can
check all the supported semantics in the following link:

#DataColumn.Expression Property
http://msdn.microsoft.com/library/de...us/cpref/html/
frlrfsystemdatadatacolumnclassexpressiontopic.asp

If you do want to do the unique item query, I think you should consider
other members suggestion that manually loop through the items and count the
distinct ones.


Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Select DISTINCT...won't select DISTINCT ryguy7272 Microsoft Access Queries 10 18th Sep 2008 08:20 PM
get distinct data from multiple sheets & then consolidate distinct =?Utf-8?B?TmlraGls?= Microsoft Excel Programming 1 18th Sep 2006 07:01 PM
uses select statement with both distinct and not distinct =?Utf-8?B?VGhlbGVlcGFu?= Microsoft Access Queries 1 8th Dec 2005 01:27 AM
Count of values in a column based on values in another column student Microsoft Excel Discussion 9 19th Aug 2004 02:30 PM
Distinct query not producing distinct results KarenM Microsoft Access 1 26th May 2004 07:41 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:31 AM.