Usually we search data by entering desired input in a control object liketextbox,comboboxetc.
After reading this post You will be able to use searching in yout project.
Drag Textbox(txtsearch) ,datagrid(dgsearch),and button named as btnsearch .Now paste below code into search buttonClick event.
private void btnsearch_Click(object sender, EventArgs e){
SqlConnection cnsearch = new SqlConnection("Data Source=.;Initial Catalog=Northwind;Integrated Security=True");
SqlDataAdapter dasearch = new SqlDataAdapter("select *from products", cnsearch);
DataSet dssearch = new DataSet();
Qsearch = "select *from products where productid = " + txtsearch.text+ "";
dasearch.SelectCommand.Connection = cnsearch;
dasearch.SelectCommand.CommandText = Qsearch;
dasearch.Fill(dssearch, "products");
dgsearch.DataSource = dssearch.Tables["products"];
}
NOTE:
if(textbox.text==integer)
{
"select *from products where productid = " + (textboxname).text + " "
//Dont forget to leave space between " + when giving name of textbox.
}
else
{
//only add single quotation at the endselect *from products where productid = ' " (textboxname).text + " ' "
}