The simple asp.net code allows you to search the database through the entering the text in textbox. The sample to search database using asp,net is given below.
protected void BtnSearch_Click(object sender, ImageClickEventArgs e)
{
SqlConnection con = new SqlConnection(_connString);
SqlCommand cmdSearch = new SqlCommand("Select cusName,cusCode from tblCustomer where cusName='" + TxtSearch.Text + "' or cusCode ='" + TxtSearch.Text + "' ", con);
SqlDataAdapter da = new SqlDataAdapter(cmdSearch);
DataTable dt = new DataTable();
da.Fill(dt);
if (dt.Rows.Count == 0)
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "RunCode", "javascript:alert('Sorry No Records Found with this Keyword.....');
document.location.href='SamePage.aspx';", true);
}
else
{
GridViewTesting.DataSource = dt;
GridViewTesting.DataBind();
}
}