使用python更新行

问题描述 投票:0回答:1

所以我在这里想编写一个python代码来更新表。就像我创建了一个名为有一些列的客户的表。我想更新从用户处获取输入的列,如果用户未提供任何输入,我希望它采用自身的先前值。请帮助我,我是python的新手。

dummy=[]
user_input=int(input("Enter the identification number you want to change:"))
First_name=input("Enter the First name:")
if len(First_name)!=0:
    dummy+="Firstname="+First_name
    cursor.execute("update customer4 set Firstname=? where identification=?")
    values=(dummy,user_input)
    conn.commit

Last_name=input("Enter the last name:")
if len(Last_name)!=0:
    if len(First_name)!=0:
        dummy+="Firstname"+First_name, "Lastname"+Last_name
        cursor.execute("update customer4 set Firstname=?, Lastname=? where identification=?")
        values=(dummy,user_input)
        conn.commit
     else:
         dummy+="Lastname"+Last_name
         cursor.execute("update customer4 set Lastname=? where identification=?")
         values=(dummy,user_input)
         conn.commit

         print(cursor.rowcount,"record affected")

这是我的python代码。在我学习python时帮助我。

python-3.x updating
1个回答
0
投票

execute()行的语法错误。使用“?”作为铺路机是正确的方法,但是您的值需要像这样插入:

cursor.execute("update customer4 set Firstname=? where identification=?", (dummy,user_input))
© www.soinside.com 2019 - 2024. All rights reserved.