2013-02-08 127 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

你不需要多集只有一个。