我如何解决此错误“缺少位置值错误”

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了我如何解决此错误“缺少位置值错误”相关的知识,希望对你有一定的参考价值。

im试图创建一个在SQL数据库中创建表并在其中创建记录的函数。 Ive传递给函数5变量,我将需要使用这些变量来创建记录。但是,不断出现“缺少5个位置参数”错误。这是下面的代码:)

def create_record(categorychoice, company_name_textbox, url_textbox, password_textbox, username_textbox):
    sql_command_table = """CREATE TABLE passwords (
    Category TEXT,
    Company TEXT,
    URL TEXT,
    Password TEXT,
    Username TEXT );"""
    crsr.execute(sql_command_table)
    sqlcreaterecord_command =  """INSERT INTO passwords (Category, Company, URL, Password, Username)
                               VALUES (categorychoice, company_name_textbox, url_textbox, password_textbox, username_textbox);"""
    crsr.execute(sqlcreaterecord_command)
    connection.commit()
答案

您可以将此代码替换为sqlcreaterecord_command

sqlcreaterecord_command =  "INSERT INTO passwords (Category, Company, URL, Password, Username) VALUES('%s', '%s', %s, '%s','%s')" % (categorychoice, company_name_textbox , url_textbox , password_textbox , username_textbox)

以上是关于我如何解决此错误“缺少位置值错误”的主要内容,如果未能解决你的问题,请参考以下文章

为什么我不能在此片段中生成唯一对象数组?

如何解决此分段错误:以下代码的 11 错误?

如何使用 Swift 使用此代码片段为 iOS 应用程序初始化 SDK?

片段活动错误中的ListView Adapter上下文,我该怎么办?

由于未找到 ID 错误的视图,列表片段未出现

如何从 Firebase 获取数据到 Recyclerview 中的片段?