The search for displaying the records
定义搜索客户(自助):连接= sqlite3.connect(“访客记录.数据库”)游标=连接.游标()
columnID = ["title","firstName","surname","dob","payment","email","address","postcode"]
columnStr =["Title","FirstName","Surname","DOB","Payment","Email","Address","Postcode"]
self.search_table = ttk.Treeview(self.search_frame,columns=columnID,show="headings")
self.search_table.bind("<Motion>","break")
for i in range(0,8):
self.search_table.heading(columnID[i],text = columnStr[i])
self.search_table.column(columnID[i],minwidth = 0, width = 108)
self.search_table.place(x=20,y=0)
for GuestRec in cursor.execute("SELECT * FROM tb1Guest1"):
self.search_table.insert("",END,values=GuestRec)
connection.commit()
connection.close()
SearchCustomer(self)
search_icon = Image.open("search icon.png")
search_icon_resize = search_icon.resize((20,20))
search_icon = search_icon_resize
search_icon_photo = ImageTk.PhotoImage(search_icon)
self.search_firstname = Entry(self.search_frame2, width=30,bg="#e2f0d9",font=("Avenir Next",18),highlightthickness = 0,relief=FLAT)
self.search_firstname.place(x = 140, y =0)
self.search_firstname_label = Label(self.search_frame2,bg = "white", text = "First Name", font=("Avenir Next",20))
self.search_firstname_label.place(x= 20,y=0)
self.search_Surname = Entry(self.search_frame2, width=30,bg="#e2f0d9",font=("Avenir Next",18),highlightthickness = 0,relief=FLAT)
self.search_Surname.place(x = 140, y =40)
self.search_Surname_label = Label(self.search_frame2,bg = "white", text = "Surname", font=("Avenir Next",20))
self.search_Surname_label.place(x= 20,y=40)
searchButton = Button(self.search_frame2, image=search_icon_photo,height = 35, width =35, command=self.Search,bg ="white")
searchButton.place(x= 500, y = 0)
“实际的搜索功能,他不工作时,试图显示结果”def搜索(自我):连接= sqlite3.connect(“访客记录.数据库”)游标=连接.游标()
第一次
Tkinter回调Traceback中出现异常错误(最近的调用在最后):文件“/库/框架/Python框架/版本/3.11/lib/python3.11/tkinter/init.py”,第1948行,在调用返回自定义函数(* 参数)中,第893行,在cmd self.cnf“命令”文件“/用户/pearcemaguire/文档/用于床和早餐的课程工作cs/床和早餐数据库需要两个.py”中,第987行,在搜索光标中的GuestRec中。执行(search_SQL,search_rec_new):第一个错误:在“AND名字LIKE”附近:语法错误
1条答案
按热度按时间h5qlskok1#
在
AND
、搜索栏和LIKE
之间添加空格:search_SQL += " AND " + search_fields[i] + " LIKE '%' || ? || '%'"
查看您收到的错误:
sqlite3.OperationalError: near "ANDsFirst_NameLIKE": syntax error
→这意味着您发送到数据库的SQL语句是“ANDsFirst_NameLIKE”而不是“AND sFirst_Name LIKE”→这是因为您在创建该SQL语句时忘记了空格。