1
String sql = `"UPDATE User Set address = '" + address +"' 
and  userType  '" + userType +"' WHERE useridNric = '" + id + "'";` 

//这不起作用(2 个字段)。ODBC 状态它缺少运算符。

String sql = "UPDATE User Set address = '" + address +"' WHERE useridNric = '" + id + "'";//但这是有效的(1个字段)

希望你们可以为这两个领域提供帮助。一直在尝试使用引号但不工作

4

4 回答 4

2

您应该AND用逗号替换,以分隔字段分配,否则它是语法错误(如果分配可以解释为比较,则为逻辑错误):

String sql = "UPDATE User Set address = '" + address +
             "',  userType  ='" + userType +
             "' WHERE useridNric = '" + id + "'"; // <<== Rewrite with parameters

不用说,您应该使用参数化 SQL 来避免 SQL 注入攻击的可能性:

String sql = "UPDATE User Set address = @address, userType = @userType "+
             "WHERE useridNric = @id"; 
于 2012-12-24T14:53:28.750 回答
0

更新多个字段时,请使用逗号分隔它们:

String sql = "UPDATE User Set address = '" + address +
                         "', userType ='" + userType +
           "' WHERE useridNric = '" + id + "'";
于 2012-12-24T14:54:12.400 回答
-1

用于,在更新查询中分隔列,如下所示:

   String sql = "UPDATE User Set address = '" + address + 
                "' , userType '" + userType + 
                 "' WHERE useridNric = '" + id + "'";
于 2012-12-24T14:54:32.933 回答
-1

在用户类型之后你不需要等号吗

String sql = "UPDATE User Set address = '" + address +"', userType = '" + userType +"' WHERE useridNric = '" + id + "'";
于 2012-12-24T14:56:56.120 回答