mardi 27 juin 2017

Select statement with textboxes and checkboxes in c#

I'm trying to build a query that will allow me to search via text box and check box at the same time , but am getting a returned value of no record each time and cannot determine why.

con.Open();


        string str = "Select * from engineering where Education = @Education AND JobNumber like '%' + @search + '%'  ";

        SqlCommand xp = new SqlCommand(str.ToString(), con);


        xp.Parameters.Add("@search", SqlDbType.NVarChar).Value = txtProjectNumber.Text;
        xp.Parameters.Add("@Education", SqlDbType.Int).Value = chkEducational.CheckState;




        try
        {
            da = new SqlDataAdapter();
            da.SelectCommand = xp;
            da.Fill(ss);
            Showdata(pos);
            DataSet ds = new DataSet();
            da.Fill(ds, "ss");
            dataGridView1.DataSource = ds.Tables["ss"];
        }
        catch
        {
            MessageBox.Show("No Record Found");

        }
        con.Close();

above is the code to my search button. There is no need to worry about the Showdata(pos) because that is there only to scroll through the returned results. The query will work if I take out the Education = @Education , or JobNumber = '%' + @search1 + '%' , just not together for some reason. Any help on this would be greatly appreciated.




Aucun commentaire:

Enregistrer un commentaire