我得到错误的简单更新查询动态创建的表,只是不明白这里的错误是..SQL更新查询(语法错误)
C#代码:
cmd2 = new SqlCommand("UPDATE " + tname + "SET [email protected], [email protected], [email protected] WHERE [email protected]", 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
错误:
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'
错字,前'缺少空间“SET ..' –
我还建议将变量_tname_置于方括号之间,以避免将来的语法错误,如果您有一个带有某种保留字或其他非有效系统标识符的表 – Steve
@AlexK。纠正,现在我得到的错误为:附加信息:错误的语法附近')' – ashish