string strConn = WebConfigurationManager.ConnectionStrings["testConnectionString2"].ConnectionString;
SqlConnection Conn = new SqlConnection(strConn);
Conn.Open();
string nam = "%"+search.Text+"%";
string sqlproduct = "SELECT* FROM empoy WHERE name LIKE @name";
SqlCommand com = new SqlCommand(sqlproduct,Conn);
SqlDataReader dr;
com.Parameters.Add("@name",SqlDbType.NVarChar).Value=nam;
dr = com.ExecuteReader();
if (dr.HasRows)
{
DataTable dt = new DataTable();
dt.Columns.Add("test");
dt.Load(dr);
GridView1.DataSource = dt;
GridView1.DataBind();
}
dr.Close();
Tag : .NET, Ms SQL Server 2008, Web (ASP.NET), C#, VS 2010 (.NET 4.x)