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);
4

3 回答 3

2

你应该只SET在语句上使用一个子句UPDATE

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

还有一件事,请参数化您的查询以避免SQL Injection。使用Command对象。

于 2013-02-08T13:43:09.413 回答
1

不要重复SET

 String updateCmd = String.Format("UPDATE [admins] SET [authority type] = '{0}',
                    [signature] = N'{1}',  [message] = N'{2}' WHERE '{3}'", 
                    authorityType, signature, msg, condition);
于 2013-02-08T13:43:35.183 回答
0

您不需要多组,只需一组。

于 2013-02-08T13:43:36.447 回答