shoaib shamsuddin

shoaib shamsuddin

  • 1.8k
  • 370
  • 10.4k

System.Data.SqlClient.SqlException: 'Incorrect syntax near the keyword

Jun 23 2022 8:56 AM
private DataTable Search()
{
    string query1 = "SELECT WorkerID ,FirstName,Worker,Cnic,CardNumber,FlatNumber,Designation,Checkin,Checkout FROM Member";
    query1 += "where WorkerID Like '%' +@parm1+ '%'";
    query1 += "OR FirstName Like'%' +@parm1+ '%'";
    query1 += "OR Worker Like '%' +@parm1+ '%'";
    query1 += "OR Cnic Like '%' +@parm1+ '%'";
    query1 += "OR CardNumber Like '%' +@parm1+ '%'";
    query1 += "OR FlatNumber Like '%' +@parm1+ '%'";
    query1 += "OR Designation Like '%' +@parm1+ '%'";
    SqlConnection connection = new SqlConnection(myconn);
    SqlCommand cmd = new SqlCommand(query1, connection);
    cmd.Parameters.AddWithValue("@parm1", textBox1.Text);
    SqlDataAdapter sda = new SqlDataAdapter(cmd);
    DataTable dt = new DataTable();
    sda.Fill(dt);
    dgvEmp.DataSource = dt;
    return (dt);
}

 


Answers (5)