0

我试图删除用户名和书名应该匹配的特定记录,并且应该从数据库中删除该记录。代码正在运行,但数据库内的数据没有被删除。我从 tkinter 的输入字段中获取书名和用户名。然后找到该记录并将其从数据库中删除。我试图通过许多文档和差异代码。我尝试了很多差异方法,但没有一个对我有用

con=sqlite3.Connection("Booking")
cur=con.cursor()
cur.execute("create table if not exists Booking(username varchar(20),address varchar(56),mob number(10),qty number(2),Book varchar(50))")
def sdw():
            te = Tk()
            te.geometry("250x300")
            L1 = Label(text="User Name").grid(row=1, column=0)
            E1 = Entry(te)
            E1.grid(row=1, column=2)
            L5 = Label(text="book name").grid(row=5, column=0)
            E5 = Entry(te)
            E5.grid(row=5, column=2)
            def db():
                print("gh")
        
                if os.path.isfile(E1.get()):
                    
                    st="DELETE  from Booking where username='%s' and Book='%s'"%(E1.get(),E5.get())
                    cur.execute("select * from Booking where username=?", (E1.get(),))
                    a = cur.fetchall()
                    messagebox.showinfo('Find', a)
                    cur.execute(st)
                    
                    messagebox.showinfo('Find', "all booking deleted")
                    te.destroy()
                    os.system("library.py")
        
                else:
                    messagebox.showinfo("ERROR","username invalid")
            b161 = Button(text="search booking", command=db)
            b161.place(x=100, y=100)
            te.mainloop()
4

0 回答 0