?
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,406 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

It seems a simple enough task, yet I see repeated questions asking how to do it: how to pass data between two forms. In this article, I will show you the different mechanisms available for you to do just that. This article is directed towards the .N…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

770 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