我试图在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)")
我做错了。查询应该看起来像这样
cur.execute("更新产品集数量=数量-1 id =?", [self.id])