Solved

sort dataview to display distinct nrs in field? e.g. Name1, Name1, Name2  : Display Name1, Name2

Posted on 2004-09-23
5
1,399 Views
Last Modified: 2006-11-17
hi, i have a dataview and there are for e.g. 3 rows in the dataview.
MyName   MyDesc
Name1     TestData
Name1     TestData
Name2     TestData

what i need to do is determine how many distinct values are in the MyName Field.
thus it would be that the value would be 2.

how can i filter to see distinct values of a field in a dataview.
thanks!

0
Comment
Question by:jxharding
  • 2
  • 2
5 Comments
 

Author Comment

by:jxharding
Comment Utility
im using SQL Server and VB.net
0
 
LVL 10

Expert Comment

by:123654789987
Comment Utility
First u can sort the dataview using

myDataView.Sort = "MyName DESC"

Then using this code snippet. There is no direct method in Dataview.

dataTable1 = myDataView.DataTable
Dim i as int
Dim distinctCounter as int
Dim value as string
value = " "
for i = 0 to dataTable1.Rows.Count - 1
if  value == dataTable1.Rows[0]["MyName"] then
distinctCounter += 1
else
value = dataTable1.Rows[0]["MyName"]
End if
Next i

0
 
LVL 10

Accepted Solution

by:
123654789987 earned 500 total points
Comment Utility
There is small change in the code

dataTable1 = myDataView.DataTable // Get the datatable bound to the dataview
Dim i as int
Dim distinctCounter as int  //Counter of distinct names
Dim value as string  //temperoray variable
value = " "
for i = 0 to dataTable1.Rows.Count - 1
if  value == dataTable1.Rows[i]["MyName"] then
distinctCounter += 1
else
value = dataTable1.Rows[i]["MyName"]
End if
Next i


0
 
LVL 8

Expert Comment

by:rajaloysious
Comment Utility
You can use SelectDistinct method as below....
http://support.microsoft.com/default.aspx?scid=kb;en-us;326176

Cheers...
0
 

Author Comment

by:jxharding
Comment Utility
hi,
rajaloysious, i posted the accept too quickly, the link also did the job excellently.
thank you both


0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Normally the drop down box control found in the .Net framework tools is able to select just one data and value at a time, which is displayed on the text area.   But what if you want to have multiple values to be selected in the drop down box? As …
Summary Displaying images in RichTextBox is a common requirement with limited solutions available. Pasting through clipboard or embedding into RTF content only support static images.  This article describes how to insert Windows control objects int…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now