【问题标题】:pyodbc INSERT INTO from a listpyodbc 从列表中插入
【发布时间】:2015-04-08 11:16:36
【问题描述】:

我正在尝试使用列表作为值的源将数据插入到 Access mdb 文件中。

cursor.execute("select * from Components")
cursor.executemany("""
                  INSERT INTO Components
                  ([Database Number],Description, [Warehouse Code],[Supplier Code], Usage, Major1, Minor1)
                  VALUES (?,?,?,?,?,?,?)
                  """), input_list
cursor.commit()

我收到错误“TypeError:函数只需要 2 个参数(给定 1 个)”。错误是指""")行,input_list

我做错了什么?提前感谢您的帮助。

这是 input_list 的打印件

['7', '1/2"  PVC 90° Elbow', '406-005', 'SUP2', 'Y', 'PVC FS', 'PVC FS']
['7', '3/4"  PVC 90° Elbow', '406-007', 'SUP2', 'Y', 'PVC FS', 'PVC FS']
['7', '1"  PVC 90° Elbow', '406-010', 'SUP2', 'Y', 'PVC FS', 'PVC FS']
['7', '1.25"  PVC 90° Elbow', '406-012', 'SUP2', 'Y', 'PVC FS', 'PVC FS']
['7', '1.5"  PVC 90° Elbow', '406-015', 'SUP2', 'Y', 'PVC FS', 'PVC FS']
['7', '2"  PVC 90° Elbow', '406-020', 'SUP2', 'Y', 'PVC FS', 'PVC FS']

【问题讨论】:

  • 您的输入是列表列表,对吧?

标签: pyodbc executemany


【解决方案1】:

我想通了。 cursor.executemany 下的最后一行应为:

""", 输入列表)

我把右括号放错地方了

【讨论】:

    猜你喜欢
    • 2019-09-02
    • 2020-03-07
    • 1970-01-01
    • 2012-09-06
    • 1970-01-01
    • 1970-01-01
    • 2015-09-30
    • 1970-01-01
    相关资源
    最近更新 更多