我正在尝试使用 python 返回表的列名。我在这里遵循指南:https://code.google.com/archive/p/pyodbc/wikis/Cursor.wiki
for row in cursor.columns(table='Customers'):
print(row.column_name)
这会产生以下错误: “对于cursor.columns中的行(表='客户'): 类型错误:内置操作的参数类型错误”
我可以连接到数据库和表,只是不使用cursor.columns。例如,这有效:
for row in cursor.tables(table='Customers'):
print(row.table_cat)
print(row.table_type)
print(row.table_name)
这对我来说非常有效:
for col in cur.columns(table='Bearings'):
print(col[3])
原来 cur.columns 是一个元组列表,元组的索引#3 是指定表的列标题。 这是我的第一篇 StackOverflow 帖子!
将 tablename 转换为 unicode,str 对于 .columns() 无效,我经历了惨痛的教训。 传递 u'Customers' 或 unicode(表名)