简体   繁体   中英

How to update a table in SQL Server during runtime using bind variable with a placeholder like '?' in python using pyodbc module?

I am writing a function which would save the records updated in the GUI which is made using Tkinter

def save():
    conn = pyodbc.connect('Driver={SQL Server};'
                          'Server=XXXXXXX;'
                          'Trusted_Connection=yes;')

After connecting to the server,`I am getting values from another function, and updating into my database here,but I am getting an error.

cursor = conn.cursor()

record_id = select_box.get()

cursor.execute("UPDATE homeaddresses SET (?,?,?,?,?,?) where id=id)",

f_name_editor.get(),
l_name_editor.get(),
address_editor.get(),
city_editor.get(),
state_editor.get(),
pincode_editor.get())

conn.commit()

conn.close()

Should be something like

cursor.execute("UPDATE homeaddresses SET f_name=?,l_name,address=?,city=?,state=?,pincode=? where id=?",

f_name_editor.get(),
l_name_editor.get(),
address_editor.get(),
city_editor.get(),
state_editor.get(),
pincode_editor.get(),
record_id )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM