首页 > 解决方案 > python sqlite插入错误

问题描述

我正在使用 python 3 tkinter 和 sqlite 我在 tkinter 中有数据Text Widget,然后我需要将其拆分并保存在数据库表中这是我的代码尝试

data = txtReceipt.get("4.0" ,"end")

 for line in data.splitlines()[2:-2]:

     no = line.split()[2:3]
     name = line.split()[1:2]
     price = line.split()[3:4]
     series = line.split()[:1]
     print(no)
     c.execute("INSERT INTO  billed_items(item_name,billed_qty,price,item_bill_series) VALUES(?,?,?,?)",(name),(no),(price),(series))
     conn.commit()

TypeError: function takes at most 2 arguments (5 given) 但是当我尝试读回文本小部件时,我也收到此错误消息任何帮助

    su=c.execute("SELECT * FROM billed_items")
    for row in su:
            text = str(row)
            txtReceipt.insert("end",str(row[0])+"  "+str(row[1])+'\t\t'+str(row[2])+'\t'+"  "+str(row[3])+"\n")

在那里它只读取表中的最后一行我不知道为什么他不能读取所有行

标签: pythontkinter

解决方案


这些值需要在元组中提供。尝试这个

query = ("INSERT INTO  billed_items(item_name,billed_qty,price,item_bill_series) VALUES(?,?,?,?)")
c.execute(query,((name),(no),(price),(series))
conn.commit()

// sqlite3.OperationalError: near "%": 语法错误?


推荐阅读