【问题标题】:Getting error "sqlite3.OperationalError: near ")": syntax error"收到错误“sqlite3.OperationalError:靠近“)”:语法错误“
【发布时间】:2020-07-04 08:33:50
【问题描述】:

我正在尝试从 GUI 向数据库添加数据并使用 SQLite 并收到此错误

Tkinter 回调异常 回溯(最近一次通话最后): 调用中的文件“C:\Users\max\AppData\Local\Programs\Python\Python37\lib\tkinter__init__.py”,第 1705 行 返回 self.func(*args) 文件“C:\Users\max\Documents\compsci stuff\NEW COMPSCI.py”,第 196 行,在 get_items C.execute(sql ,vari) sqlite3.OperationalError:靠近“)”:语法错误

  def get_items(self,*args,**kwargs): #this function gets the items from the entry boxes

        self.carmake= self.carmake_e.get()

        self.carmodel= self.carmodel_e.get()

        self.regi= self.regi_e.get()

        self.colour= self.colour_e.get()

        self.cost= self.cost_e.get()

        self. tcost= self. tcost_e.get()

        self.sellprice= self.sellprice_e.get()

        self.assumedprofit= self.assumedprofit_e.get()

        if self.carmake == " or self.carmodel" == "== self.colour == ":
            print ("WRONG")
            TKInter.messagebox.showinfo("error", "please enter values for car make, model and colour")
        else:
            print ("solid m8")
            sql= "INSERT INTO inventory(car_make,car_model, registration_plate,colour,cost,total_cost,selling_price,assumed_profit) VALUES) (?,?,?,2,?,?,2,?)"
            vari=(self.carmake, self.carmodel,self.regi,self.colour,self.cost,self.tcost,self.sellprice,self.assumedprofit)
            C.execute(sql ,vari)
            C.execute(sql(self.name,self.carmake, self.carmodel, self.regi,self.colour, self.cost,self.tcost,self.sellprice,self.assumedprofit))
            conn.commit()
            tkinter.messagebox.showinfo("success", "succesfully added to databse!")

【问题讨论】:

    标签: python sqlite tkinter


    【解决方案1】:

    你在这一行多了一个括号

    sql= "INSERT INTO inventory(car_make,car_model, registration_plate,colour,cost,total_cost,selling_price,assumed_profit) VALUES) (?,?,?,2,?,?,2,?)"
    

    VALUES) 应该是VALUES

    【讨论】:

      猜你喜欢
      • 2021-05-11
      • 2019-02-07
      • 2020-02-06
      • 2019-01-12
      • 2014-05-17
      • 2021-10-19
      • 2018-07-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多