How can I link a textbox to a mysql database from visual studio 2010 c #?

0

Hi, I'm a university student and I have a project that deals with a point of sale, I have a problem with linking a textbox with my mysql database, I previously linked a combobox but I do not know how to link a textbox, AYUDAAAAA Link from combobox to mysql ...

 string consulta = string.Format("select nombre from productos where tipo=2");
                //MessageBox.Show(consulta);
                MySqlCommand comando = new MySqlCommand(consulta, conexion);
                MySqlDataReader lector = comando.ExecuteReader();

                while (lector.Read())
                {
                    comboBox4.Items.Add(lector.GetString(0));

                }
    
asked by Saul 12.04.2017 в 00:46
source

2 answers

1

I'm not sure if I understood you

but I think that what you want is to feed the result of your SELECT a textBox:

while (lector.Read()){
    textBox1.text=lector.GetString(0);
}

keep in mind that if you have more than one record in the answer to your query the textbox will only show the last one.

    
answered by 12.04.2017 / 01:12
source
0

Good day, yes, I need my textbox to be fed according to what I have in my database, but even with your answer, I can not get the textbox to feed, will the data type have something to do with it? I am using a FLOAT data type or I will be coding badly, then I show the part of the code ... I add your contribution

string consulta2 = string.Format("select Precio from Productos");
                //MessageBox.Show(consulta);
                MySqlCommand comando2 = new MySqlCommand(consulta, conexion);
                MySqlDataReader lector2 = comando.ExecuteReader();

                while (lector.Read())
                {

                    textBox1.Text = lector.GetString(0);


                }
    
answered by 13.04.2017 в 16:56