Click here to Skip to main content
15,921,660 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have Database tables from Accesses called ConductorsWI when i make reading from it using filter parameters by filed callled "Type" and filed2 called "Shape" and put the result on called "SSize" on combobox3, the results come random and i looking to order them

i have sizes 1.5, 2, 4, 6, 8, 10, 12, .... etc from database
put it appear on combobox as 10, 12, 6, 3, 4, 25, .... Random
and i need to make them sorted from small to big

may be because when i chose reading from database with the cariteria it random it
but i need finally to sort it again

What I have tried:

Dim Cmd As New OleDbCommand 'cmd as command to use
            Cmd.Connection = conn 'open connection to database
            Cmd.CommandText = "select * from ConductorsWI where Type = '" & ComboBox1.SelectedItem & "' and Shape = '" & ComboBox2.SelectedItem & "'"

            conn.Open() 'open connection
            dr = Cmd.ExecuteReader
            While dr.Read

                ComboBox3.Items.Add(dr("SSize").ToString())

            End While
            dr.Close()
            conn.Close()
Posted
Updated 19-Jun-20 6:11am
Comments
Richard Deeming 19-Jun-20 11:58am    
Your code is vulnerable to SQL Injection[^]. NEVER use string concatenation to build a SQL query. ALWAYS use a parameterized query.

Everything you wanted to know about SQL injection (but were afraid to ask) | Troy Hunt[^]
How can I explain SQL injection without technical jargon? | Information Security Stack Exchange[^]
Query Parameterization Cheat Sheet | OWASP[^]

Cmd.CommandText = "select * from ConductorsWI where Type = @Type And Shape = @Shape"
Cmd.Parameters.AddWithValue("@Type", ComboBox1.SelectedItem)
Cmd.Parameters.AddWithValue("@Shape", ComboBox2.SelectedItem)
katkot_rewsh 19-Jun-20 12:40pm    
its works but without ordering of SSize from database
i need combobox3 to load with SSize but to be sorted
1.5
3
4
6
7
8
9
it is not happened

1 solution

Quote:
put it appear on combobox as 10, 12, 6, 3, 4, 25, .... Random
and i need to make them sorted from small to big

Have a look here: SQL ORDER BY[^]
SQL tutorial : SQL Tutorial[^]
 
Share this answer
 
Comments
katkot_rewsh 19-Jun-20 12:36pm    
i am actually using Accesses not SQL
How i can add the ORDER BY DESC at my syntex ???
Patrice T 19-Jun-20 12:49pm    
Access is the name of the database server, SQL is the query language.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900