I have been making a python project using tkinter. I am also using SQLite3 database(tables). The project has a function to update the database, but the messagebox throws an exceptional error.I tried to remove the exception code but still the database won't get updated.
the database name is: 'criminal_records'.
#update code
def update_data(self):
if self.var_case_id.get()=="":
messagebox.showerror('Error','All fields are required')
else:
try:
update=messagebox.askyesno('Update', "Are you sure you want to update this record?")
if update>0:
conn=sqlite3.connect('criminal_records.db')
my_cursor=conn.cursor()
my_cursor.execute('UPDATE criminal_records SET Case ID=?, Criminal Name=?,Case Number=?,Date of crime=?, Crime Type=?, Description=?,Block=?,Location=?,Arrest Date=?, Age=?, Gender=?, WHERE Case Id=?', (
self.var_case_id.get(),
self.var_name.get(),
self.var_case_number.get(),
self.var_date_of_crime.get(),
self.var_crime_type.get(),
self.var_description.get(),
self.var_block.get(),
self.var_location.get(),
self.var_arrest_date.get(),
self.var_age.get(),
self.var_gender.get(),
))
else:
if not update:
return
conn.commit()
self.fetch_data()
self.clear_data()
conn.close()
messagebox.showinfo('Successful', 'Criminal record has been updated')
except Exception as es:
messagebox.showerror('Error',f'Due to{str(es)}')
OUTPUT
You have to quote the column names that contain spaces with backticks.
You also have an extra
,
beforeWHERE
, and you're missing the value forWHERE `Case ID`=?
in the parameter tuple.