首页 > 解决方案 > Sqlite3 在查找数据时给出错误 2 个参数 (7given)

问题描述

def addPersonRec(Firstname, Surname, DoB, Age, Notes, DateCreated):
    con=sqlite3.connect("silver.db")
    cur = con.cursor()
    cur.execute("INSERT INTO silver VAULES (NULL, ?, ?, ?, ?, ?, ?)", Firstname, Surname, DoB, Age, Notes, DateCreated)
    con.commit()
    con.close()

所以我的问题是我已经引入了 sqlite 3,当我运行它时,我在 addPersonRec cur.execute("INSERT INTO silver VAULES (NULL, ?, ?, ?, ?, ?, ?)",Firstname , Surname, DoB, Age, Notes, DateCreated)
TypeError: function take at most 2 arguments (7 given) 请任何想法帮助

标签: pythonsqlite

解决方案


.execute的第二个参数应该是一个元组。

另请注意,您有一个错字。VAULES应该是VALUES

cur.execute("INSERT INTO silver VALUES (NULL, ?, ?, ?, ?, ?, ?)",
            (Firstname, Surname, DoB, Age, Notes, DateCreated))

推荐阅读