vendredi 11 novembre 2016

check value from SQL to enable textbox and label

I have a WinForm app in C# in witch i need to hide some textboxes and labels depending on the item selected on the previous form. I disabled the textboxes and labels in the designer and would make them visible again depending on a value from a SQL table. The code i have is this one but i cant figure out how to check the value.

    con.Open();
    SqlCommand cmd = con.CreateCommand();
    cmd.CommandType = CommandType.Text;
    cmd.CommandText = "select prumos from dbo.modelos";
    cmd.ExecuteNonQuery();
    if () ; //database value prumos =2
    {
        textBox13.Visible = true;
        textBox18.Visible = true;
        textBox17.Visible = true;
        label16.Visible = true;
        return;
    }
    else if () ; //database value prumos = 3 
    {
        textBox13.Visible = true;
        textBox18.Visible = true;
        textBox17.Visible = true;
        textBox14.Visible = true;
        textBox16.Visible = true;
        textBox15.Visible = true;
        label16.Visible = true;
        label20.Visible = true;
        return;
    }

Can anyone help please,

Thanks in advance.

Aucun commentaire:

Enregistrer un commentaire