Skip to content
Advertisement

what is the syntax error in this SQL update query in asp.net c#? [closed]

I am getting error in simple update query for dynamically created table,just can’t understand what the error here is..

c# code:

cmd2 = new SqlCommand("UPDATE " + tname + "SET ans=@ans, sans=@sans, chk=@chk WHERE qno=@qno", con99);
            cmd2.Parameters.AddWithValue("@ans", ans);
            cmd2.Parameters.AddWithValue("@sans", sans);
            cmd2.Parameters.AddWithValue("@chk", chk);
            cmd2.Parameters.AddWithValue("@qno", qno);
            cmd2.ExecuteNonQuery(); //error showing here in vstudio

Error:

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 ‘ans’

Advertisement

Answer

You are missing a space after the table name and you have an unnecessary closing parentheses :

"UPDATE " + tname + " SET ans=@ans, sans=@sans, chk=@chk WHERE qno=@qno"
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement