0

Cannot update data in Python. I use Access as Database. What is an error?

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')

a = Entry (form, width=20, font="Arial 16")
a.pack ()
b = Entry (form, width=20, font="Arial 16")
b.pack ()

def Add ():
    cursor.execute ("UPDATE Laws SET Law_name = a, Fine = b", (a.get(), b.get()))
    con.commit ()
    cursor.close ()
    con.close ()


Button=Button(form, text = 'PUSH ME', command = Add)
Button.pack ()

form.mainloop ()

The error is

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/UPDATE.py", line 19, in Add
    cursor.execute ("UPDATE Laws SET Law_name = a, Fine = b", (a.get(), b.get()))   File "C:\Users\HP\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pypyodbc-1.3.4-py3.6.egg\pypyodbc.py", line 1491, in execute
    self._BindParams(param_types)   File "C:\Users\HP\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pypyodbc-1.3.4-py3.6.egg\pypyodbc.py", line 1284, in _BindParams
    raise ProgrammingError('HY000',error_desc) pypyodbc.ProgrammingError: ('HY000', 'The SQL contains 0 parameter markers, but 2 parameters were supplied')

1 Answer 1

3

Use parameter markers:

cursor.execute ("UPDATE Laws SET Law_name = ?, Fine = ?", (a.get(), b.get()))
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.