2013-02-08 123 views
1

什麼是這個代碼錯誤的查詢,錯誤

String updateCmd = String.Format(@"UPDATE [admins] 
    SET [authority type] = '{0}', 
    SET [signature] = N'{1}', 
    SET [message] = N'{2}' 
    WHERE '{3}'", authorityType, signature, msg, condition); 

回答

2

錯誤的事情,你應該只UPDATE語句中使用一個SET條款「附近的SET語句語法錯誤」。

UPDATE [admins] 
SET [authority type] = '{0}', 
    [signature] = N'{1}', 
    [message] = N'{2}' 
WHERE '{3}' 

一兩件事,請做參數化查詢以避免SQL Injection。使用Command對象。

+0

非常感謝:)你是我的男人:) – 2013-02-08 14:22:31

+0

不客氣':D' – 2013-02-08 14:23:57

1

不要重複SET

String updateCmd = String.Format("UPDATE [admins] SET [authority type] = '{0}', 
        [signature] = N'{1}', [message] = N'{2}' WHERE '{3}'", 
        authorityType, signature, msg, condition); 
0

你不需要多集只有一個。