An exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll but was not handled in user code
Additional information: Incorrect syntax near the keyword 'WHERE'.
I dont know where is the wrong in the syntax !!
using( var command1 = new SqlCommand("INSERT INTO Employee(EmpPhone,Password,OfficeNo,Floor, Building) VALUES (@EmpPhone,@Password,@OfficeNo,@Floor, @Building) WHERE EmpID ='" + id.Text + "'", con))
{
command1.Parameters.AddWithValue("@EmpPhone", Convert.ToInt32(phone.Text));
command1.Parameters.AddWithValue("@Password", password.Text);
command1.Parameters.AddWithValue("@OfficeNo", officeNo.Text);
command1.Parameters.AddWithValue("@Floor", Convert.ToInt32(floor.Text));
command1.Parameters.AddWithValue("@Building", Convert.ToInt32(building.Text));
command1.ExecuteNonQuery();
}
As unlimit said, you can't use
WHERE
clause inINSERT
statement. Here it's syntax;I feel like you try to update existing row. If it is, you should use
UPDATE (Transact-SQL)
statement like;I also have similar problems in visual studio 2013*
Problem is still unidentified. What actually you want to achieve, a new row or update an existing row.
In case of insert:
Update:
Yes "Insert" command can only insert a new row into your table and you cannot modify/update your table using insert command. Use "Update" command to update your row that is already present in your table