Show SQL Data in TextBox

1

In this code it shows me 3 data with the same number of folio and the same department, with the help of a listBox , however I want it to also be shown in 3 textbox that I have (Obviously the data that will show are 3 different, such as listBox )

       public void listSMTQA()
    {
        DateTime hoy = DateTime.Now;
        string folioid = hoy.ToString("ddMMyy");
        cn.Open();
        SqlCommand comando = new SqlCommand("Select SMT from tbl_Issues where folio='" + folioid + "' and Dpto='Quality'", cn);
        SqlDataReader leer;
        leer = comando.ExecuteReader();
        while (leer.Read() == true)
        {
            listBox3.Items.Add(leer[0].ToString());
            //Aqui quiero que los muestre tambien
            textBox5.Text = leer["SMT"].ToString();
            textBox6.Text = leer["SMT"].ToString();
            textBox7.Text = leer["SMT"].ToString();
        }
        cn.Close();
    }
    
asked by CarlosR93 14.03.2017 в 21:32
source

1 answer

1

Dear if you already have in the ListBox the items in the database from there you can take them to assign them to your textbox, I leave a small code may be useful. Greetings.

 public void listSMTQA()
{
    DateTime hoy = DateTime.Now;
    string folioid = hoy.ToString("ddMMyy");
    cn.Open();
    SqlCommand comando = new SqlCommand("Select SMT from tbl_Issues where folio='" + folioid + "' and Dpto='Quality'", cn);
    SqlDataReader leer;
    leer = comando.ExecuteReader();
    while (leer.Read() == true)
    {
        listBox3.Items.Add(leer[0].ToString());

    }
    cn.Close();
//Si ya tienes todos los valores en la lista, entonces los puedes
//sacar de ahí también, y no te saldran repetidos y podrás agregar
//el primero, el segundo y el tercero al elemento que quieras.
//listBox3.Items[0].Text; le pasarás el texto que es visible para el cliente
//si le pasas listBox3.Items[0].Value; le pasarás el valor que le agregaste
//  ese atributo y no es visible para el cliente. 

if(listBox3.Items.Count > 0){

}
        textBox5.Text = listBox3.Items[0].Text;
        textBox6.Text = listBox3.Items[1].Text;
        textBox7.Text = llistBox3.Items[2].Text;
}
    
answered by 15.03.2017 / 20:25
source