protected void Button1_Click(object sender, EventArgs e)
{
string query = "select * from aspnet_Users where userName like '%@UserName%'";
connection.Open();
SqlCommand command = new SqlCommand(query, connection);
command.Parameters.Add("@UserName", SqlDbType.NVarChar).Value = TextBox1.Text;
SqlDataReader reader = command.ExecuteReader();
GridView1.DataSource = reader;
GridView1.DataBind();
connection.Close();
}
I am trying to use connected model to search a user's data in a table but the GridView is always, never fills with data.
LIKEtolike '%' + @UserName+ '%'"'%@UserName%'will be taken as a literal comparison and the value of the parameter will not be replaced.DECLARE @UserName VARCHAR(10) ='hi' SELECT'%@UserName%' ,'%' +@UserName + '%'