Click here to Skip to main content
15,896,063 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i am having a problem while calling value from a column to a combobox. i am using mysql with a table emp having employee detail id,name,address,contact

i am using the code
VB
cnn = New MySqlConnection
cnn.ConnectionString = ("server=localhost;userid=root;password=root;database=hello")

Try
            cnn.Open()
            Dim query As String
            query = "SELECT * from hello.emp"
            cmd = New MySqlCommand(query, cnn)
            rdr9 = cmd.ExecuteReader
            While rdr9.Read
                Dim adr = rdr9.GetString("address")
                ComboBox1.Items.Add(adr)
            End While
            cnn.Close()
        Catch ex As MySqlException
            MessageBox.Show(ex.Message)
        Finally
            cnn.Dispose()
        End Try

this code shows the address in the combobox but if there are 8 entries of same address it shows 8 items of same name like:
calcutta
delhi
delhi
delhi
calcutta
delhi
Posted
Updated 9-Jul-14 4:22am
v2
Comments
nilesh sawardekar 12-Jul-14 5:14am    
"but is there any other way to call first and remove selected items"
whats this mean?explain in brief

Try
SQL
query = "SELECT distinct address from hello.emp"
 
Share this answer
 
query = "SELECT DISTINCT address from hello.emp" & ComboBox1.Text & ""
i used the above code while calling the items and it worked

but is there any other way to call first and remove selected items
 
Share this answer
 
Comments
CHill60 9-Jul-14 19:08pm    
You're lucky I spotted this... don't post solutions to respond ... use either the "Have a Question or Comment?" or "Reply" link as appropriate.
Yes - in theory you "could" populate the comboBox and then start removing items - but that would be the wrong approach. The solution I've suggested works well, does exactly what you need and is efficient. Not sure where your "& ComboBox1.Text & "" has come from... don't do that ... use parameterised queries instead ... see give-me-parameterized-sql-or-give-me-death/[^]
Hi You can use the Distinct fro this ..

SQL
query = "SELECT distinct address from hello.emp"
 
Share this answer
 
Comments
[no name] 11-Jul-14 10:28am    
Copying and pasting someone else's solution as if it were your own is so not cool. And it's abuse.

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