Search Using Combo box

Asked

Viewed 37 times

0

I’m with a ComboBox that when I select Active or Inactive status it empties my DataGrid What I’d like him to do is select one of the two Options and bring all records with Active Status, for an example

code that I’m using :

private void comboBox1_SelectedValueChanged_1(object sender, EventArgs e)
    {
        string strSelect = "SELECT * FROM Produto WHERE status LIKE (@status)";
        using (MySqlConnection conn = new MySqlConnection("server=127.0.0.1;database=ProdPacote; Uid=root; pwd=1234;"))
        {
            MySqlDataAdapter da = new MySqlDataAdapter(strSelect, conn);
            //Passagem por parâmetros.
            da.SelectCommand.Parameters.AddWithValue("@status", comboBox1.SelectedValue);
            DataSet ds = new DataSet();
            da.Fill(ds, "status");
            dataGridView1.DataSource = ds.Tables["status"];
        }
    }

1 answer

0

Well solved I managed to bring data from DataGrid as follows I changed the comboBox1.SelectedValue for comboBox1.text, now it brings only records with Active or Inactive status

follows code below:

private void comboBox1_SelectedValueChanged_1(object sender, EventArgs e)
    {
        string strSelect = "SELECT * FROM Produto WHERE status LIKE (@status)";
        using (MySqlConnection conn = new MySqlConnection("server=127.0.0.1;database=ProdPacote; Uid=root; pwd=1234;"))
        {
            MySqlDataAdapter da = new MySqlDataAdapter(strSelect, conn);
            //Passagem por parâmetros.
            da.SelectCommand.Parameters.AddWithValue("@status", comboBox1.Text + "%");
            DataSet ds = new DataSet();
            da.Fill(ds, "status");
            dataGridView1.DataSource = ds.Tables["status"];
        }
    }

Browser other questions tagged

You are not signed in. Login or sign up in order to post.