Python 在sqlite值中插入变量

Python 在sqlite值中插入变量,python,database,sqlite,Python,Database,Sqlite,我写的代码是: import sqlite3 def insert_product(product): with sqlite3.connect("main.db") as db: cursor = db.cursor() sql=("insert into Products(CatID,Name,Qty,Price)values(?, ?, ?, ?)", (ID,Name,Qty,Price) ) cursor.execute(sql,

我写的代码是:

import sqlite3
def insert_product(product):
    with sqlite3.connect("main.db") as db:
        cursor = db.cursor()
        sql=("insert into Products(CatID,Name,Qty,Price)values(?, ?, ?, ?)", (ID,Name,Qty,Price) )
        cursor.execute(sql,product)
        db.commit()

if __name__ == "__main__":
    ID= int(input("enter the CatID of the product:>> "))
    Name = input("Enter the name of the Product you want to inssert: >>")
    Qty = int(input("Enter the quantity of the stock available: >>"))
    Price = int(input("Enter the price of the product: >>"))
    product = (ID,Name,Qty,Price)
    insert_product(product)
我想使用ID、Name、Qty和Price的输入值在数据库中插入这些值,但它给了我以下错误:

文件“C:\Users\Admin\OneDrive\sql\insert\U product.py”,insert\U product中的第6行 cursor.execute(sql、产品) ValueError:操作参数必须为str


sql
应该是字符串而不是元组,您已经在
product
中有了参数:

    sql = "insert into Products (CatID,Name,Qty,Price) values (?, ?, ?, ?)"
    cursor.execute(sql, product)

@SaqibMalik你说它什么都不做是什么意思?您是否在用户输入后检查了数据库,并注意到用户条目已添加到数据库中?为我工作。。