[英]Update database error in python with sqlite3
我正在嘗試執行通過表單更新數據庫的功能,但出現此錯誤: ValueError: operation parameter must be str
。
我對其他功能(如刪除,讀取或插入)沒有問題,我也不知道如何解決此問題。 我記下了兩個版本的函數更新和相應的錯誤。
我正在嘗試:
def actualizaDatos():
Id1 = clave.get()
nombre1 = nombre.get()
password1 = password.get()
apellido1 = apellido.get()
direccion1 = direccion.get()
comentarios1 = comentarios.get()
sentencia="UPDATE DATOSUSUARIOS SET ID= ?, NOMBRE_USUARIO = ?, PASSWORD = ?, APELLIDO = ?, DIRECCION = ?, COMENTARIOS = ? WHERE ID=?", [clave.get()]
miCursor.execute(sentencia, [Id1, nombre1, password1, apellido1, direccion1, comentarios1])
我希望數據庫進行更新,但出現此錯誤:
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\John\AppData\Local\Programs\Python\Python37-32\lib\tkinter\__init__.py", line 1705, in __call__
return self.func(*args)
File "Practica_Guiada.py", line 148, in actualizaDatos
miCursor.execute(sentencia, [Id1,nombre1, password1, apellido1, direccion1, comentarios1])
ValueError: operation parameter must be str
你不需要[clave.get()]
在分配結束sentencia
。 將變量設置為元組,而不是SQL字符串。
您的miCursor.execute()
調用中也沒有足夠的參數。 有7個?
在SQL中,但在參數列表中只有6個元素。 您需要重復Id1
因為它在開頭和結尾(但是實際上,不需要設置ID
,因為您只需將其設置為已經具有的相同值即可)。
def actualizaDatos():
Id1 = clave.get()
nombre1 = nombre.get()
password1 = password.get()
apellido1 = apellido.get()
direccion1 = direccion.get()
comentarios1 = comentarios.get()
sentencia="UPDATE DATOSUSUARIOS SET NOMBRE_USUARIO = ?, PASSWORD = ?, APELLIDO = ?, DIRECCION = ?, COMENTARIOS = ? WHERE ID=?"
miCursor.execute(sentencia, [nombre1, password1, apellido1, direccion1, comentarios1, Id1])
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.