Can't search for a record in sqlite database using tkinter as a gui to enter the name of the record I am searching for (Python) -
i making program library using database store details books, tkinter gui. feature of program user can enter name of book , search database , return records books containing name. here code have feature:
def booksearch(event): top = toplevel() top.title("book search") label(top, text = "enter name of book searching for: ").grid() booksearchentry = entry(top) booksearchentry.grid(row = 0, column = 1) getrecord = c.execute("select * booklist bookname = (?)", booksearchentry.get()) def printrecords(event): row in getrecord: t = text(top, height = 400, width = 50) t.pack() t.insert(end, getrecord) booksearchbutton = button(top, text = "search", command = printrecords) booksearchbutton.grid(row = 0, column = 1)
i getting error message:
getrecord = c.execute("select * booklist bookname = (?)", booksearchentry.get()) sqlite3.programmingerror: incorrect number of bindings supplied. current statement uses 1, , there 0 supplied.
i have seen other posts saying add comma make tuple
getrecord = c.execute("select * booklist bookname = (?)", booksearchentry.get,())
i still error message, however, it's error message:
getrecord = c.execute("select * booklist bookname = (?)", booksearchentry.get,()) typeerror: function takes @ 2 arguments (3 given)
i have been stuck on ages, appreciated, thanks
i think because second argument execute method has tuple. should write as:
getrecord = c.execute("select * booklist bookname = (?)", (booksearchentry.get(),))
Comments
Post a Comment