gpt4 book ai didi

python - 如何在数据库中输入值?

转载 作者:搜寻专家 更新时间:2023-10-30 19:47:24 26 4
gpt4 key购买 nike

import easygui as eg
import sqlite3``

conn = sqlite3.connect('ATM.sqlite')
print("Connected to database successfully")
conn.execute("CREATE TABLE if not exists CUSTOMER(ID INTEGER, Name TEXT, Address TEXT, Mobile_no INTEGER, PIN INTEGER, Balance INTEGER)")

def Admin_AddUser():
options = ['ID', 'Name', 'Address', 'Mobile No.', 'PIN']
Current_bal = 0
value = eg.multenterbox('Enter the information for new user', 'Add User', options)
conn.execute('INSERT INTO CUSTOMER (ID, Name, Address, Mobile_no, PIN, Balance) VALUES'
'( value[0],value[1],value[2],value[3],value[4],int(Current_bal))')

我想在客户表中输入详细信息。但它向我显示以下错误。

    sqlite3.OperationalError: near "[0]": syntax error

最佳答案

data =  [value[0],value[1],value[2],value[3],value[4],int(Current_bal)]

cursor.execute('INSERT INTO CUSTOMER (ID, Name, Address, Mobile_no, PIN, Balance) VALUES ( ?,?,?,?,?,?)', data)

关于python - 如何在数据库中输入值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49643326/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com