尝试了(?)和(%s),但似乎没有效果。我哪里错了?
def update(phone,name):
conn = sqlite3.connect(db)
print ("\nOpened database for updates successfully")
sql = "UPDATE VARUN set PHONE = %s where NAME= %s "
print (sql)
conn.execute(sql,(phone,name))
'''
conn.execute("UPDATE VARUN set PHONE = (?) where NAME= (?) ",(phone,name));
'''
conn.commit()
-----调用函数----
contactlist[selection()]=[nameVar.get(), phoneVar.get()]
updt = (contactlist[selection()])
name = (updt[0])
phone = (updt[1])
print (name,phone)
try:
update(name,phone)
except:
tkinter.messagebox.showwarning("cannot be blank")
else:
setList ()
saveContact()
答案 0 :(得分:2)
首先,您正在使用bare except clause,这会阻止您查看函数引发的错误。删除它,看看它是如何失败的。
并且,您需要?
个占位符而不包含左括号:
def update(phone, name):
conn = sqlite3.connect(db)
cursor = conn.cursor()
print ("\nOpened database for updates successfully")
sql = "UPDATE VARUN set PHONE = ? where NAME= ?"
cursor.execute(sql, (phone, name))
conn.commit()