Solved

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

Posted on 2004-09-23
5
1,404 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 500 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

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

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

IP addresses can be stored in a database in any of several ways.  These ways may vary based on the volume of the data.  I was dealing with quite a large amount of data for user authentication purpose, and needed a way to minimize the storage.   …
Flash (http://en.wikipedia.org/wiki/Adobe_Flash) has evolved over the years to where it has become a masterful tool for displaying content screen.  It has excellent layout placement, UI precision as well as rendering capabilities. This, along with t…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

749 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