Search only one record type in the database and show in Datagrid

Asked

Viewed 41 times

1

How do you do a bank search and show on DataGrid, only that I select a category

I’m not sure how to do this kind of search in the bank, when I select in the ComboBox1 the active word, it brings me only the active products, however I wanted to make my textBox search only the name of active products.

let’s assume that I have two products with the same name, but one is active and the other inactive, if I select active it seeks only this name that is active

code I’m using(at least trying to do this):

 private void txtBusca_TextChanged(object sender, EventArgs e)
    {
        if(comboBox1.Text == "Ativo")
        {
            string strSelect = "SELECT * FROM Produto WHERE Nome LIKE (@Nome)";

            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("@Nome", txtBusca.Text + "%");
                DataSet ds = new DataSet();
                da.Fill(ds, "Nome");
                dataGridView1.DataSource = ds.Tables["Nome"];
            }
        }
  • But what exactly is the problem? Could you elaborate further on your question?

  • @Joãomartins edited the question, please see if it is better to understand

1 answer

2


You have to use in your query another filter to bring you only the assets, assuming this is already marked in the Product table.

string strSelect = "SELECT * FROM Produto WHERE Nome LIKE (@Nome) AND Activos=true";
  • Guy I think is almost it however it is still giving error, I register the product as active (selecting a checkbox) on the bench has a column of Status where it is marked if this active or inactive

  • I tried to give an adapted so string strSelect = "SELECT * FROM Produto WHERE Nome AND status='Ativo' LIKE (@Nome)";&#But he brought me no record

  • here by the logic you sent adapted and got, worth XD string strSelect = "SELECT * FROM Produto WHERE status='Ativo' AND nome LIKE (@Nome)";

Browser other questions tagged

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