我得到錯誤的簡單更新查詢動態創建的表,只是不明白這裏的錯誤是..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