没有错误产生,但记录不会在数据库中更新

时间:2019-04-03 10:00:52

标签: python sql sqlite

def amendStaff(): 
    global STAFFIDVar,STAFF_FORENAMEVar,STAFF_SURNAMEVar,STAFF_DOBVar,STAFF_CONTACTVar,STAFF_EMAILVar,STAFF_ADDRESSVar,STAFF_POSTCODEVar
#getting the variable from the entry form
STAFFID=STAFFIDVar.get()
STAFF_FORENAME = STAFF_FORENAMEVar.get()
STAFF_SURNAME = STAFF_SURNAMEVar.get()
STAFF_DOB = STAFF_DOBVar.get()
STAFF_CONTACT = STAFF_CONTACTVar.get()
STAFF_EMAIL = STAFF_EMAILVar.get()
STAFF_ADDRESS = STAFF_ADDRESSVar.get()
STAFF_POSTCODE = STAFF_POSTCODEVar.get()

conn=sqlite3.connect('Database.db') #opens the database
cursor = conn.execute('SELECT * FROM STAFF')
cursor.execute('UPDATE STAFF SET STAFF_FORENAME = ? ,STAFF_SURNAME=? ,STAFF_DOB = ? , STAFF_CONTACT=? ,STAFF_EMAIL=?, STAFF_ADDRESS=?  ,STAFF_POSTCODE=? WHERE STAFFID = ?', (STAFFID,STAFF_FORENAME,STAFF_SURNAME,STAFF_DOB,STAFF_CONTACT,STAFF_EMAIL,STAFF_ADDRESS,STAFF_POSTCODE))
#amends the record
conn.commit() #saves the changes
conn.close() #closes the database
messagebox.showinfo("DATABASE ACTION",str("Record Updated"))

1 个答案:

答案 0 :(得分:1)

更新中的参数顺序混乱,工作人员编号在最后,应该在最后。