4
Answers

Search from DB with LIKE Operator

Mohit Kapoor

Mohit Kapoor

8y
290
1
 I am getting an incorrect syntax error on following code .
There's an error in Sql query ?
 
protected void btnByName_Click(object sender, EventArgs e)
        {
            string name = txtByName.Text.Trim();

            Response.Write("clicked \n");
            cmd.Connection = con;
          
            cmd.CommandText = "select * from books where name LIKE '%'  "+name+"  '%'  ";
            
            con.Open();
            rdr=cmd.ExecuteReader();
          
          if(rdr.Read())
            {
               Response.Write(" found <br>");
                    GridView1.DataSource = rdr;
                    GridView1.DataBind();
            }
            else
                Response.Write("no match found");
             con.Close();

            

        }
Answers (4)