Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ms-access/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python SQL更新查询:应为字符串或整数地址,而不是实例_Python_Sql Server_Sql Update_Pyodbc_Pypyodbc - Fatal编程技术网

Python SQL更新查询:应为字符串或整数地址,而不是实例

Python SQL更新查询:应为字符串或整数地址,而不是实例,python,sql-server,sql-update,pyodbc,pypyodbc,Python,Sql Server,Sql Update,Pyodbc,Pypyodbc,我使用Python2.7和PyODBC来运行SQL查询,但每当我使用Python运行更新查询时 cursor.execute("UPDATE tbl_User SET gender = ? WHERE id = 1", ['male']) 我得到一个错误: TypeError: string or integer address expected instead of instance instance 如果我直接在SQL Server上运行相同的查询,它也可以工作。如何: gender =

我使用Python2.7和PyODBC来运行SQL查询,但每当我使用Python运行更新查询时

cursor.execute("UPDATE tbl_User SET gender = ? WHERE id = 1", ['male'])
我得到一个错误:

TypeError: string or integer address expected instead of instance instance
如果我直接在SQL Server上运行相同的查询,它也可以工作。

如何:

gender = 'male'
cursor.execute("UPDATE tbl_User SET gender = {:s} WHERE id = 1".format(gender))
还要确保sqlite的python版本与SQL Server使用的版本相同。对于python,有一种类型:

import sqlite3
print(sqlite3.sqlite_version)

问题是我没有在查询的末尾加分号。解决办法是:

cursor.execute("UPDATE tbl_User SET gender = ? WHERE id = 1;", ['male'])

您是否能够在不将参数传递并硬编码到UPDATE语句的情况下使其工作?您的意思是:cursor.execute(“UPDATE tbl_User SET gender='male',其中id=1”)?是的,只是为了确保代码可以通过pyodbc执行。:)我得到了错误:/但是正如我所说的,如果我直接在SQL Server上运行它,它确实可以工作。我得到了错误:pypyodbc.ProgrammingError:(u'42S22',u“[42S22][Microsoft][ODBC SQL Server Driver][SQL Server]无效的列名'male')。您可能需要修改您的答案并将其标记为包含您正在使用的数据库,因为这似乎是特定于数据库的。啊,这是有道理的。SQL Server对这些分号非常坚决,但我已经有一段时间没有使用它了,所以我没有意识到这一点。