Solved

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

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

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