python更新查询减去列

时间:2019-03-17 10:24:57

标签: python pyodbc

我尝试在python中运行sql查询以更新数量,但出现错误。

cur.execute(
  "UPDATE Products SET Price =? , Quantity =? , RackLocation =? WHERE ID =?",
   [self.new_price.get(), self.new_quantity.get(), self.new_racklocation.get(), self.id]
)

我遇到此错误:

[int(self.new_quantity.get()) ,  int(self.id)])    
pyodbc.ProgrammingError: ('42000', "[42000] [Microsoft][ODBC SQL Server Driver]
[SQL Server]Incorrect syntax near '='. (102) (SQLExecDirectW); [42000] 
[Microsoft][ODBC SQL Server Driver][SQL Server]Statement(s) could not be 
prepared. (8180)")

1 个答案:

答案 0 :(得分:0)

我做错了。查询应如下所示

cur.execute(“更新产品设置数量=数量-1 WHERE ID =?”,                     [self.id])

相关问题