在数据库中输入值

时间:2018-04-04 08:27:16

标签: database python-3.x sqlite

import easygui as eg
import sqlite3

# ----------------------------------------------------
# Enabling connection to database
conn = sqlite3.connect('ATM.sqlite')
print("Connected to database successfully")
conn.execute("CREATE TABLE if not exists Info(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
    values = eg.multenterbox('Enter the information for new user', 'Add User', options)
    conn.execute("INSERT INTO Info (ID, Name, Address, Mobile_no, PIN, Balance)VALUES(?, ?, ?, ?, ?, ?)"),[values[0], values[1], values[2], values[3], values[4], Current_bal]


loop = True
while loop:
    ch1 = eg.buttonbox('Welcome to the ATM portal, continue as you desire', '', ['Admin', 'Customer', 'Exit'])
    if ch1 == 'Admin':
        AdminPortal()

    else:
        loop = False

# Terminating connection to database
conn.commit()
conn.close()
print("Terminated connection to database successfully")

错误: sqlite3.ProgrammingError:提供的绑定数量不正确。当前语句使用6,并且提供了0。 为什么会出现此错误?请帮忙。

1 个答案:

答案 0 :(得分:1)

你在关闭括号时的错误。否则,你的代码行是如此之大,可能很难看出错误。下面的小代码更容易理解

 sql = "INSERT INTO Info (ID, Name, Address, Mobile_no, PIN, Balance)VALUES(?, ?, ?, ?, ?, ?)"
 values = [values[0], values[1], values[2], values[3], values[4], Current_bal]
 conn.execute(sql, values)