C# DELETE FROM Parameter problem
-
Hi. I have a local db with a number of tables. One is a table with filenames. This method is supposed to remove the file from the database table HiddenFile with the id sent to the method. I have been trying to solve this for a long time without success. The code is:
public bool DeleteFile(Int32 identity) { string connString = "Data Source=(LocalDB)\\\\MSSQLLocalDB;AttachDbFilename=C:\\\\Code\\\\FileDB.mdf;Integrated Security=True;Connect Timeout=30"; SqlConnection dbConn = new SqlConnection(connString); dbConn.Open(); using (SqlCommand com = new SqlCommand("DELETE FROM HiddenFile WHERE Id = @Identity)", dbConn)) { com.Parameters.AddWithValue("@Identity", identity); com.ExecuteNonQuery(); } dbConn.Close(); return true; }
When I run it, there is an error: "Incorrect syntax near ')'". Can anybody see what the problem is?
-
Hi. I have a local db with a number of tables. One is a table with filenames. This method is supposed to remove the file from the database table HiddenFile with the id sent to the method. I have been trying to solve this for a long time without success. The code is:
public bool DeleteFile(Int32 identity) { string connString = "Data Source=(LocalDB)\\\\MSSQLLocalDB;AttachDbFilename=C:\\\\Code\\\\FileDB.mdf;Integrated Security=True;Connect Timeout=30"; SqlConnection dbConn = new SqlConnection(connString); dbConn.Open(); using (SqlCommand com = new SqlCommand("DELETE FROM HiddenFile WHERE Id = @Identity)", dbConn)) { com.Parameters.AddWithValue("@Identity", identity); com.ExecuteNonQuery(); } dbConn.Close(); return true; }
When I run it, there is an error: "Incorrect syntax near ')'". Can anybody see what the problem is?
"DELETE FROM HiddenFile WHERE Id = @Identity)" <- you have here an unnecessary closing parenthesis...remove it...
Skipper: We'll fix it. Alex: Fix it? How you gonna fix this? Skipper: Grit, spit and a whole lotta duct tape.