0

When the below function is executed,

 def UpdateMed(self):
        if self.refmed_var.get()=="" or self.addmed_var.get()=="":
            messagebox.showerror("Error","All Fields are Required")
        else:
            conn=mysql.connector.connect(user='root', password='*****',
                                host='localhost', database='mydata',
                                auth_plugin='mysql_native_password')
            my_cursor=conn.cursor()
            s="UPDATE pharma SET MedRef=%s where Ref=%s"
            b1=(self.refmed_var.get(),self.addmed_var.get())
            my_cursor.execute(s,b1)
            conn.commit()
            self.fetchdata_med()
            conn.close()
            
            messagebox.showinfo("Success","Medicine Has been updated")

The following error is raised:

mysql.connector.errors.DataError: 1292 (22007): Truncated incorrect DOUBLE value: 'Medicne2'

How to fix this?

pharma table structure:

Ref        int(_)
MedRef     varchar(250)
cd-snehil
  • 19
  • 3
  • Did you check the content and `type` of `self.refmed_var` and `self.addmed_var`? – gimix Aug 10 '21 at 16:31
  • @gimix I am passing 'Medicne2' which is a valid Varchar character and Ref is INT. I dont think this is the problem here. Its some kind of bug. Refer to: https://stackoverflow.com/questions/3456258/mysql-truncated-incorrect-double-value?rq=1 If i manually add 'Medicne2' (including the ' ') it end up fine but when I use the query from python it sends 'Medicne2' without the ' '. This is the problem. – cd-snehil Aug 10 '21 at 18:07
  • I see... really a misleading error message. But well, add the single-quotes then – gimix Aug 10 '21 at 18:21

0 Answers0