0

I have this current code which writes data into entry boxes. I am trying to create a feature which selects what is in the boxes and updates the record in the table, Trainers. This is the current code:

 def Update(self):

    global Record
    global Name
    global TrainerID
    global Postcode
    global Age
    global Gender
    global Password

    (Name, TrainerID, Postcode, Age, Gender, Password) = tuple(Record)

    Name = self.ent_Name.get()
    TrainerID = self.ent_TrainerID.get()
    Postcode = self.ent_Postcode.get()
    Age = self.ent_Age.get()
    Gender = self.ent_Gender.get()
    Password = self.ent_Password.get()

    List = [Name, TrainerID, Postcode, Age, Gender, Password]

    self.cur.execute("UPDATE Trainers SET Name=?, TrainerID=?, Postcode=?,Age,=? Gender=?, Password=?",((Name,) (TrainerID,) (Postcode,) (Age,) (Gender,) (Password,)))

This is the error:

File "E:\Program\TrainerAccounts.py", line 194, in Update self.cur.execute("UPDATE Trainers SET Name=?, TrainerID=?, Postcode=?,Age,=? Gender=?, Password=?",((Name,) (TrainerID,) (Postcode,) (Age,) (Gender,) (Password,))) TypeError: 'tuple' object is not callable

  • First of all, what is the error you get? have a look at: https://stackoverflow.com/questions/5082452/python-string-formatting-vs-format – R4PH43L Feb 26 '18 at 15:41
  • You've told us what you want, but haven't explained what problem you're having. Is this code throwing an error? Is it storing the wrong data? – Bryan Oakley Feb 26 '18 at 15:44
  • It isn't updating the record in the database, the error is: `sqlite3.OperationalError: near "WHERE": syntax error` – evansciaran Feb 26 '18 at 15:50
  • what you have the is trying to update only one record `TrainerID=?` but you several db columns you want to update `(Name, TrainerID, Postcode, Age, Gender, Password)` – AD WAN Feb 26 '18 at 15:55
  • create a minimal code to debug it and also do want to update only `TrainerID` or all the columns. – AD WAN Feb 26 '18 at 15:56

1 Answers1

0

Since you didn't post minimal code am assuming this what you want to update for the TrainerID

 self.cur.execute("UPDATE Trainers WHERE TrainerID=?",(TrainerID),)

if you want to update all the record do this

 self.cur.execute("UPDATE Trainers SET Name=?, TrainerID=?, Postcode=?, Age=?, Gender=?, Password=?",(Name, TrainerID, Postcode, Age, Gender, Password)
AD WAN
  • 1,414
  • 2
  • 15
  • 28