?
Solved

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

Posted on 2004-09-23
5
Medium Priority
?
1,409 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
ID: 12131572
im using SQL Server and VB.net
0
 
LVL 10

Expert Comment

by:123654789987
ID: 12131773
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 2000 total points
ID: 12131781
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
ID: 12131908
You can use SelectDistinct method as below....
http://support.microsoft.com/default.aspx?scid=kb;en-us;326176

Cheers...
0
 

Author Comment

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


0

Featured Post

NEW Veeam Backup for Microsoft Office 365 1.5

With Office 365, it’s your data and your responsibility to protect it. NEW Veeam Backup for Microsoft Office 365 eliminates the risk of losing access to your Office 365 data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Simulator games are perfect for generating sample realistic data streams, especially for learning data analysis. It is even useful for demoing offerings such as Azure stream analytics, PowerBI etc.
Integration Management Part 2
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

809 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