![](/img/trans.png)
[英]Failed to run query: SQLSTATE[42000]: [Microsoft][SQL Server Native Client 11.0][SQL Server]Incorrect syntax near ')'
[英]ERROR [42000] [Microsoft][SQL Native Client][SQL Server]Incorrect syntax near the keyword 'SET'
我們使用 SQL 2005 Express 進行存儲。
我正在使用 ODBCCommand 更新表中的一些值,但出現以下錯誤。 表包含所有有效列。
ERROR [42000] [Microsoft][SQL Native Client][SQL Server] Incorrect syntax near the keyword 'SET'.
所以請讓我知道它有什么問題,查詢在 SQL 瀏覽器中運行良好。
我的代碼:
cmd = new OdbcCommand("UPDATE Transaction_Details SET SubscriptionCancelled=? WHERE SubscriptionID=?", conn);
cmd.Parameters.Add("@SubscriptionCancelled", OdbcType.VarChar, 255).Value = "Subscription Cancelled on " + DateTime.Now;
cmd.Parameters.Add("@SubscriptionID", OdbcType.VarChar, 255).Value = sSubscriptionID;
我以前沒有使用過 ODBCcommand,但我猜你需要在命令語句中用單引號分隔你的字符串。
嘗試更改為:
cmd = new OdbcCommand("UPDATE Transaction_Details SET SubscriptionCancelled='?' WHERE SubscriptionID='?'", conn);
改變
UPDATE Transaction_Details SET SubscriptionCancelled=? WHERE SubscriptionID=?
至
UPDATE Transaction_Details SET SubscriptionCancelled=@SubscriptionCancelled WHERE SubscriptionID=@SubscriptionID
鑒於 SQL 不知道參數的類型,因為您正在構建 T-SQL 語句而不是使用參數化查詢,因此字符串周圍可能需要引號?
我還沒有機會對此進行測試,但這是一個快速的嘗試建議。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.