I have created a custom tkinter app and allow the user to update their data. Even thought the message popup the Record Updated, but the SQLite database seem did not change. Where am I go wrong? How am I fix it?
What I have tried:
def update():
selected_item = row_selector.get()[0][0]
print(selected_item)
my_name = name.get()
print(my_name)
my_class = class1.get()
print(my_class)
my_mark = mark1.get()
print(my_mark)
my_gender = gender.get()
print(my_gender)
my_address = address.get("1.0", "end")
print(my_address)
my_hostel = hostel.get()
print(my_hostel)
try:
sql = text("""UPDATE student_address SET name = :name, class = :class,
mark = :mark, gender = :gender, address = :address, hostel = :hostel
WHERE id = :id""")
with engine.connect() as my_conn:
my_cursor = my_conn.execute(sql,
{"name": my_name,
"class": my_class,
"mark": my_mark,
"gender": my_gender,
"address": my_address,
"hostel": my_hostel,
"id": selected_item})
CTkMessagebox(title="Update", message="Record Updated!")
my_conn.commit()
except SQLAlchemyError as e:
print(f"An error occurred: {e}")
CTkMessagebox(title="Error",
message="Please select a record to update",
icon="cancel")
btn6_update = ctk.CTkButton(bottom_frame,
fg_color='purple',
state='disabled',
font=font1,
hover_color="black",
text_color='white',
text="Update",
command= update)
btn6_update.grid(row=5,column=6, padx=20)