Query side, you can try this:
Replace Type with the column that holds your values.
SELECT * From Table ORDER BY Type ASC
For list based, try this:
Dim lstString As New List(of String)
'Add the items to your list
lstString.Sort()
'The default sort function sorts Ascending - for sorting of another type - write your sort function and pass it into the sort's parameters.
Then to load them into the textbox, you can do this:
For i = 0 to lstString.Count - 1
If i < lstString.Count - 1 Then
TextBox1.Text &= lstString(i) & ", "
Else
TextBox1.Text &= lstString(i)
End If
Next
Begginnerdev
Practically a Posting Shark
864 posts since Apr 2010
Reputation Points: 184
Solved Threads: 142
Skill Endorsements: 8
On the following table
Supplies
ID
Name
Containing the following rows
1 paper
2 book
3 book
4 book
5 pen
6 pencil
7 pencil
8 pen
The following query
select count(*) as count,Name from supplies group by Name order by count desc
returns
3 book
2 pen
2 pencil
1 paper
Then you can pick the three most frequent items from most to least frequent by stepping through the returned recordset until you have three items or you run out of records.
Reverend Jim
Carpe per diem
3,614 posts since Aug 2010
Reputation Points: 563
Solved Threads: 452
Skill Endorsements: 32
For the following code you need to create ListView1 in details view with two columns. It will add up to three rows to the listview with the most frequent items appearing first.
ListView1.Items.Clear()
Dim con As New SqlConnection("Server=.\SQLEXPRESS;Database=mydb;Trusted_Connection=yes;")
Dim cmd As New SqlCommand
con.Open()
cmd.Connection = con
cmd.CommandText = "select count(*) as count,Name from supplies group by Name order by count desc"
Dim rdr As SqlDataReader = cmd.ExecuteReader
Do While rdr.Read() And ListView1.Items.Count < 3
ListView1.Items.Add(New ListViewItem({rdr("count"), rdr("Name")}))
Loop
rdr.Close()
con.Close()
Reverend Jim
Carpe per diem
3,614 posts since Aug 2010
Reputation Points: 563
Solved Threads: 452
Skill Endorsements: 32
In that case
TextBox1.Text = ""
Dim con As New SqlConnection("Server=.\SQLEXPRESS;Database=mydb;Trusted_Connection=yes;")
Dim cmd As New SqlCommand
con.Open()
cmd.Connection = con
cmd.CommandText = "select count(*) as count,Name from supplies group by Name order by count desc"
Dim rdr As SqlDataReader = cmd.ExecuteReader
Do While rdr.Read() And ListView1.Items.Count < 3
TextBox1.Text &= rdr("Name") & " "
Loop
rdr.Close()
con.Close()
Reverend Jim
Carpe per diem
3,614 posts since Aug 2010
Reputation Points: 563
Solved Threads: 452
Skill Endorsements: 32
Question Answered as of 4 Months Ago by
Reverend Jim,
azareth,
BhuvanRam
and 1 other