I am using a datagridview for the output of the results and I have made 4 combobox each have its condition, asceding and descending, starts and contains with, search from table..
I am writing this with lots of code, is there any way to make this short?
string bncw = "select * from Book where Book_Title LIKE '%' + @searchinput + '%'";
string bncwa = "select * from Book where Book_Title LIKE '%' + @searchinput + '%'";
string bnbw = "select * from Book where Book_Title LIKE ' +@searchinput +'%'";
if (cb2.SelectedItem.ToString() == "Book")
{
cmd = new SqlCommand(bncw, con);
cmd.Parameters.Add("@searchinput", SqlDbType.NVarChar).Value = inputsearch.Text;
da = new SqlDataAdapter(cmd);
ds = new DataSet();
da.Fill(ds);
dataGridView1.DataSource = ds.Tables[0];
if (cb1.SelectedItem.ToString() == "Name contains with")
{
cmd = new SqlCommand(bncw, con);
cmd.Parameters.Add("@searchinput", SqlDbType.NVarChar).Value = inputsearch.Text;
da = new SqlDataAdapter(cmd);
ds = new DataSet();
da.Fill(ds);
dataGridView1.DataSource = ds.Tables[0];
if (cb3.SelectedItem.ToString() == "Ascending Order")
{
}
}
}
else if (cb1.SelectedItem.ToString() == "Name begins with")
{
cmd = new SqlCommand(bnbw, con);
cmd.Parameters.Add("@searchinput", SqlDbType.NVarChar).Value = inputsearch.Text;
da = new SqlDataAdapter(cmd);
ds = new DataSet();
da.Fill(ds);
dataGridView1.DataSource = ds.Tables[0];
}