How to avoid duplicate data in a combobox?

-2

Good day, I have an error with my project, it turns out that in my combobox I have registered 4 products, but when I change the selection and return to it, these products are duplicated, how can I correct that? I'm working on windows form linked to a MYSQL database

string consulta = string.Format("Select precio from productos where nombre='Pacifica012'");
        string consulta2 = string.Format("Select precio from productos where nombre='GRG170DX'");
        string consulta3 = string.Format("Select precio from productos where nombre='Stratocaster S'");
        //MessageBox.Show(consulta);

        MySqlCommand comando = new MySqlCommand(consulta, conexion);
        MySqlCommand comando2 = new MySqlCommand(consulta2, conexion2);
        MySqlCommand comando3 = new MySqlCommand(consulta3, conexion3);

        MySqlDataReader lector = comando.ExecuteReader();
        MySqlDataReader lector2 = comando2.ExecuteReader();
        MySqlDataReader lector3 = comando3.ExecuteReader();

        while (lector.Read())
        {

                textBox5.Text = lector.GetString(0);
        }
        while (lector2.Read())
        {

                textBox5.Text = lector2.GetString(0);
        }
        while (lector3.Read())
        {

                textBox5.Text = lector3.GetString(0);
        }
    
asked by Saul 25.04.2017 в 17:25
source

1 answer

0

It must be that you are loading the data of the products before a show or similar event; you should look for another item or first check if the combobox is already full, or first empty it before filling it.

    
answered by 25.04.2017 в 17:29