【发布时间】:2021-12-10 00:48:36
【问题描述】:
我正在尝试从名为 Template、Table clients 的数据库中更新记录。我从 Tkinter Treeview 获取更新信息。我正在更新除 user_id 之外的任何字段,这是我的主键。我在 cur.execute(sql_command) 上收到语法错误。 cur 被定义为我的光标。
# Function to Edit Record
def edit_client():
# Update the Database
print(user_id_box.get())
sql_command = ("UPDATE clients SET \
f_name = f_name_box.get(),\
l_name = l_name_box.get(),\
email = email_box.get(),\
phone = phone_box.get(),\
price = price_box.get(),\
address = address_box.get(),\
city = city_box.get(),\
state = state_box.get(),\
country = country_box.get(),\
zipcode = zipcode_box.get() WHERE user_id = user_id_box.get()")
# Execute the SQL command
cur.execute(sql_command)
# Commit the changes to the database
mydb.commit()
# Clear the old entry
clear_record()
# Refresh the Data Frame
query_database()
【问题讨论】:
-
不是缩进错误?我可以看到您在
sql_command之后的每一行都忘记了一个空格。
标签: python mysql tkinter sql-update