I have built a GUI using TKinter. There I want to output the stored data and change them individually. Using the UPDATE command, I want to update the data in the table. I use MariaDB as database.
I’m getting this error:
xException in Tkinter callback Traceback (most recent call last): File "C:UsersZlatanAppDataLocalProgramsPythonPython39libtkinter__init__.py", line 1892, in __call__
return self.func(*args) File "C:UsersZlatanPycharmProjectspythonProjectpolymertssr.py", line 296, in update
c.execute("""UPDATE tssr SET TypeError: Argument 2 must be Tuple or List!
Here is the complete function:
# create update function
def update():
# connect to database
conn = mariadb.connect(
user="root",
password="pass",
host="127.0.0.1",
port=3306,
database="polymer"
)
# create cursor
c = conn.cursor()
record_id = select_box.get()
c.execute("""UPDATE tssr SET
Order_name = :order_name,
Operator_name = :operator_name,
Sample = :sample,
Strain = :strain
WHERE ID = :ID""",
{
'order_name': Order_name_editor.get(),
'operator_name': Operator_name_editor.get(),
'sample': Sample_editor.get(),
'strain': Strain_editor.get(),
'ID': record_id
})
# commit changes
conn.commit()
# close connection
conn.close()
Any suggestions where I’m doing wrong?
Advertisement
Answer
As the error suggests, the 2nd argument of execute()
should be a list
or a tuple
, while you’re using a dict
. Try this:
c.execute("""UPDATE tssr SET
Order_name = %s,
Operator_name = %s,
Sample = %s,
Strain = %s
WHERE ID = %s""",
(
Order_name_editor.get(),
Operator_name_editor.get(),
Sample_editor.get(),
Strain_editor.get(),
record_id
)
)