尝试添加到.db文件时出现Python SQLite错误

时间:2013-12-09 15:30:16

标签: python sqlite

运行程序并尝试插入数据时出现此错误:

'sqlite3.OperationalError: near ")": syntax error'

我的代码如下:

import sqlite3
def insert_data(values):
    with sqlite3.connect("mrsimms.db")as db:
        cursor = db.cursor()
        sql ='Insert into Stock(Name,Type,RetailPrice,NumberInStock,)values(?,?,?,?,?)'
        cursor.execute(sql,values)
        db.commit()

if __name__ == "__main__":
    add = "y"
    while add == "y":
        Name = input("Please enter the Name: ")
        Type = input("Please enter the type of product: ")
        RetailPrice =input("Retail Price: ")
        NumberInStock = input('Please enter the amount in stock: ')
        AddNewStock = (ProductID,Name,Type,RetailPrice,NumberInStock)
        print(AddNewStock)
        insert_data(AddNewStock)
        add = input("Do you wish to add another record? (y/n) ")
        print()

任何帮助将不胜感激!

0 个答案:

没有答案