Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have already create tkinter window in which i am having a TypeError : not enough arguments to format string

What I have tried:

def update():

    a = Emp_NO.get()
    b = Name.get()
    c = Address.get()
    d = Attendance.get()
    e = Bank_Name.get()
    f = Account_NO.get()
    g = Basic_Pay.get()
    h = Net_Pay.get()

    # Create a database or connect to one
    mydb = pymysql.connect(host="localhost",user="root",passwd="mypasswd",db="mydb")
    # Create cursor
    mycursor = mydb.cursor()
    
    sql = "UPDATE Payslip SET Emp_NO=%s , Name=%s , Address=%s , Attendance=%s , Bank_Name=%s , Account_NO=%s , Basic_Pay=%s , Net_Pay=%s WHERE Emp_NO=%s"


     val = (a,b,c,d,e,f,g,h)

    mycursor.execute(sql,val)
    
    #Commit Changes
    mydb.commit()

    #Close connection
    mydb.close()

    editor.destroy() #to disappear the update window
Posted
Updated 23-Nov-20 22:52pm
v2

1 solution

Quote:
Python
sql = "UPDATE Payslip SET Emp_NO=%s , Name=%s , Address=%s , Attendance=%s , Bank_Name=%s , Account_NO=%s , Basic_Pay=%s , Net_Pay=%s WHERE Emp_NO=%s" # 9 placeholders

val = (a,b,c,d,e,f,g,h) # 8 parameters
As the error says, you haven't provided enough parameters.

You could append the Emp_NO parameter a second time:
Python
val = (a,b,c,d,e,f,g,h,a)
But it doesn't make sense to update a column to the same value it's already set to.
Python
sql = "UPDATE Payslip SET Name=%s , Address=%s , Attendance=%s , Bank_Name=%s , Account_NO=%s , Basic_Pay=%s , Net_Pay=%s WHERE Emp_NO=%s"

val = (b,c,d,e,f,g,h,a)
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900