-1

I am using python 3 tkinter and sqlite I have data inside tkinter Text Widget and then i need to split and save it in a data base table here is my code attempts

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()

but i am getting this error message TypeError: function takes at most 2 arguments (5 given) any help please here also when i am trying to read back into text widget

    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")

in there it only reads the last row in the table i dont know why he cant read all the rows

1 Answers1

2

The values need to be provided in a tuple. Try this

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 "%": syntax error?

static const
  • 953
  • 4
  • 16