代码之家  ›  专栏  ›  技术社区  ›  Berch

尝试将数据插入sqlite3时出错-绑定参数0时出错-可能是不支持的类型

  •  0
  • Berch  · 技术社区  · 6 年前

    我试图将Kivy的textinput字段中的数据插入sqlite3数据库,但出现了以下问题。代码段

    def save(self):
    
        conn = Database.db_connect()
        cursor = conn.cursor()
    
        # kivy textinput widgets are assigned variable no, name
        no = self.empid_text_input
        name = self.empname_text_input.text
    
        try:
            save_index_sql="INSERT INTO EmpInfo (EmpID , EmpName) VALUES (?,?)"
            conn.execute(save_index_sql, (no, name)) # Causes Error
            conn.commit()
            conn.close()
        except sqlite3.IntegrityError as e:
            print("Error: ",e)
    

    #抛出错误----->sqlite3.InterfaceError:绑定参数0时出错-可能是不支持的类型。

    1. 创建表EmpInfo(EmpID integer主键,EmpName text NOT NULL)

    2. EmpImage公司 创建表EmpImage(EmpID integer主键,EmpPhoto BLOB NOT NULL)

            # conn.execute(save_index_sql,(int(no), str(name))) # RETURNS----> TypeError: int() argument must be a string, a bytes-like object or a number, not 'TextInput'
            # conn.execute(save_index_sql, (str(no), str(name))) # RETURNS----> Error:  datatype mismatch
    
    1 回复  |  直到 6 年前
        1
  •  1
  •   Ozzy Walsh    6 年前

    您正在尝试插入 TextInput 要插入 文本输入框

    还必须将其转换为 integer

    更改:

    no = self.empid_text_input

    收件人:

    no = int(self.empid_text_input.text)