'Update database using selected treeview row

I am trying to update my sqlite3 database by selecting a specific row in the Treeview and editing it, so I can update it in the database using primary key autoincrement id the problem: The update is not applied to the sqlite3 database it only applied to Treeview. I have tried the following:

def buying_checks_only_payment(self): #unimportant treeview info's self.buying_checkspaymenttree['columns'] = ("اdate", "اvalue", "checknum"اcheckid")

add values into treeview

def buying_addcheck(self): self.checksrecords=[] self.checkid += 1

     self.buying_checkspaymenttree.insert("", 'end', values=(
        self.buying_check_date_var.get(), self.buying_check_value_var.get(),
        self.buying_check_num_var.get(), self.checkid,self.makevar.get(),self.sellernamevar.get(),self.Buyingdate_var.get(),self.cashepayments.get(),self.buying_nocheckpic))

for child in self.buying_checkspaymenttree.get_children(): self.checksrecords.append(self.buying_checkspaymenttree.item(child)["values"])

#add treeview values into database trying to use the primry key as self.rowid

def buying_checksdb(self): self.conn = sqlite3.connect('car dealership.db') self.cursorObj = self.conn.cursor()

for self.checksrecords in self.checksrecords:
    self.cursorObj.execute(
     "INSERT INTO cars_buying_checksonly (checkdate, checkvalue, 
     checknum, carmake, Sellername, buyingdate, entirepaymentmethod, 
     checkpic)values(?,?,?,?,?,?,?,?)",
     (self.checksrecords[0], self.checksrecords[1], 
      self.checksrecords[2], self.checksrecords[3],
      self.checksrecords[4], self.checksrecords[5], 
      self.checksrecords[6], self.checksrecords[7]))
     self.conn.commit()
enter code here
     self.rowid=self.cursorObj.lastrowid
     print(self.rowid)

#trying to select the row and edit it in treeview to update it in the database def buying_editcheck(self): self.conn = sqlite3.connect('car dealership.db') self.cursorObj = self.conn.cursor()

self.buying_selected_check_edit = 
self.buying_checkspaymenttree.selection()[0]
    print(self.buying_checkspaymenttree.item(self.buying_selected_check_edit)['values'])
 uid = 
self.buying_checkspaymenttree.item(self.buying_selected_check_edit) 
['values'][0]

self.buying_checkspaymenttree.item(self.buying_selected_check_edit, 
values=(
=self.buying_check_date_var.get(),self.buying_check_value_var.get(), 
self.buying_check_num_var.get(),self.checkid))

#is using self.rowid instead of self.checkid can help?

self.cursorObj.execute("UPDATE cars_buying_checksonly SET 
checkdate=?,checkvalue=?, checknum=? WHERE uid=?", 
(self.buying_check_date_var.get(),self.buying_check_value_var.get(),                 
self.buying_check_num_var.get(),uid,)) 

self.conn.commit()

Important: if you can help post your answer post your comment, if you can't please do not bother me with how to post my code, posting my question here was the last choice, I have been stuck in this for a while and used all my energy to solve it and when I Lost the hope, I posted it here, so please if you don't want to help me with it don't send me anything that could add insult to injury



Solution 1:[1]

Solution is:

self.buying_checkspaymenttree.item(self.buying_selected_check_edit) 
['values'][0], # specifying column that id value inserted in, in my situation 
['values'][3], # due to the language that I am using in the GUI, 
               # I am using a language from Right to left.

Conclusion: Using autoincrement id to edit your code or delete it and selected your row by using the column that has the id value.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 ouflak