pypyodbc 无法使用 SQL Server Localdb 引用列名
pypyodbc Can't refer to column names using SQL Server Localdb
总 Python 菜鸟在这里。我正在针对 sql 服务器本地数据库编写脚本,无法根据列名调用值。
cnxn = pypyodbc.connect('Driver={SQL Server Native Client 11.0};Server=(localdb)\database;integrated security = true')
cursor = cnxn.cursor()
cursor.execute("SELECT username FROM [students].[dbo].[users]")
rows = cursor.fetchall()
for row in rows:
print (row.username)
cnxn.close()
returns AttributeError: 'Row' 对象没有属性 'username'
print (row)
按预期转储数据。并将代码修改为:
cursor.execute("SELECT username FROM [students].[dbo].[users]")
rows = cursor.fetchall()
x=0
for row in rows:
print (row.cursor_description[x][0])
cnxn.close()
returns 每条记录的用户名。
为什么我打不通row.username?
总 Python 菜鸟在这里。我正在针对 sql 服务器本地数据库编写脚本,无法根据列名调用值。
cnxn = pypyodbc.connect('Driver={SQL Server Native Client 11.0};Server=(localdb)\database;integrated security = true')
cursor = cnxn.cursor()
cursor.execute("SELECT username FROM [students].[dbo].[users]")
rows = cursor.fetchall()
for row in rows:
print (row.username)
cnxn.close()
returns AttributeError: 'Row' 对象没有属性 'username'
print (row)
按预期转储数据。并将代码修改为:
cursor.execute("SELECT username FROM [students].[dbo].[users]")
rows = cursor.fetchall()
x=0
for row in rows:
print (row.cursor_description[x][0])
cnxn.close()
returns 每条记录的用户名。
为什么我打不通row.username?