无法通过python删除数据。我使用 Entry
来删除。也许 Entry
没有在删除时使用,那么有什么问题吗?
from tkinter import *
import pypyodbc
import ctypes
#Create connection
con = pypyodbc.connect('DRIVER={Microsoft Access Driver (*.mdb)};UID=admin;UserCommitSync=Yes;Threads=3;SafeTransactions=0;PageTimeout=5;MaxScanRows=8;MaxBufferSize=2048;FIL={MS Access};DriverId=25;DefaultDir=C:/Users/HP/Desktop/PITL;DBQ=C:/Users/HP/Desktop/PITL/PITL.mdb;')
cursor = con.cursor ()
form=Tk ()
form.title ("Add data")
form.geometry ('400x200')
lab_1=Label(form, text="What do you want to delete?")
lab_1.pack ()
en_1=Entry(form, width=20,bd=5)
en_1.pack()
def Add ():
cursor.execute ("DELETE FROM Laws WHERE Law_name = ?", (en_1.get()))
con.commit ()
cursor.close ()
con.close ()
Button=Button(form, text = 'PUSH ME', command = Add)
Button.pack ()
form.mainloop ()
Exception in Tkinter callback Traceback (most recent call last):
File "C:\Users\HP\AppData\Local\Programs\Python\Python36-32\lib\tkinter__init__.py", line 1699, in call return self.func(*args) File "C:\Users\HP\Desktop\PITL\DELETE.py", line 21, in Add cursor.execute ("DELETE FROM Laws WHERE Law_name = ?", (en_1.get())) File "C:\Users\HP\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pypyodbc-1.3.4-py3.6.egg\pypyodbc.py", line 1475, in execute raise TypeError("Params must be in a list, tuple, or Row") TypeError: Params must be in a list, tuple, or Row
最佳答案
只需写入一个元组或行。为了确保它是一个元组,请使用逗号:
cursor.execute ("DELETE FROM Laws WHERE Law_name = ?",
(en_1.get(), )) #<- this comma
关于python - 无法在 Access by Python 中删除数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48666092/