I am trying to use the wildcard query to display rows in a gridview but it is not up to the mark…
protected void Button1_Click(object sender, EventArgs e)
{
SqlCommand com = new SqlCommand("select * from Alphabates where Word
like'"+TextBox1.Text+"'", new SqlConnection("data source=
USER\\SQLEXPRESS;initial catalog=vicky;integrated
security=true"));
try
{
com.Connection.Open();
GridView1.DataSource = com.ExecuteReader();
GridView1.DataBind();
com.Connection.Close();
com.Connection.Dispose();
}
catch (SqlException ex)
{
Label1.Text = ex.Message;
}
}
try this:
Change your query to add % around the text box value
wildcard search requires a % sign to get the desired result, other wise it would be same as using an equal to(=) sign
As per your comment if you want rows starting with given word then:
Ex:
is same as
so you should change it to