发现很难将我的数据库链接到我的GUI。全名未定义?

时间:2019-05-07 10:33:47

标签: python ms-access

尝试将数据库与大学项目的GUI链接。我是python的新手。目前,我收到一个全名未定义的错误。我知道这可能很简单。它应该在一个半小时内到期,所以我想把id丢在这里,看看会发生什么。预先感谢大家。

def saveUser(self):
     name = self.fullname.get()
     email = self.email.get()
     marketing = self.optin.get()
     vehicle = self.vehicle_class.get()
     account_type = self.video.get()

     new_member = customer([fullname], email, accounttype, optin, self.video.get())
     DBfile = ".\\databaseeflow.mdb"
     conn = pypyodbc.connect(r"DRIVER={Microsoft Access Driver (*.mdb)};DBQ="+DBfile)
     cursor = conn.cursor()
     SQL = "INSERT INTO AccountList (ID, [fullName], email, optin, accounttype, vehicleclass) VALUES ('" 
     SQL = SQL + "Edin Gogic" + ",'"
     SQL = SQL + "edingogic@itb.ie" + "','"
     SQL = SQL + "1" + "','"
     SQL = SQL + "video" + "','"
     SQL = SQL + "car" + "');"

谁能看到一个明显的问题?谢谢

1 个答案:

答案 0 :(得分:0)

我找到了。单引号丢失。查看第一个条目中的引号如何丢失。应该是'Edin Gogic'而不是'Edin Gogic

class db():
    def saveUser(self):
     #name = self.fullname.get()
     #email = self.email.get()
     #marketing = self.optin.get()
     #vehicle = self.vehicle_class.get()
     #account_type = self.video.get()

     #new_member = customer([fullname], email, accounttype, optin, self.video.get())
     #DBfile = ".\\databaseeflow.mdb"
     #conn = pypyodbc.connect(r"DRIVER={Microsoft Access Driver (*.mdb)};DBQ="+DBfile)
     #cursor = conn.cursor()
     SQL = "INSERT INTO AccountList (ID, [fullName], email, optin, accounttype, vehicleclass) VALUES ('" 
     SQL = SQL + "Edin Gogic" + ",'"
     SQL = SQL + "edingogic@itb.ie" + "','"
     SQL = SQL + "1" + "','"
     SQL = SQL + "video" + "','"
     SQL = SQL + "car" + "');"
     print SQL

dbx=db()
dbx.saveUser()

以下结果:

INSERT INTO AccountList (ID, [fullName], email, optin, accounttype, vehicleclass) VALUES ('Edin Gogic,'edingogic@itb.ie','1','video','car');

在这里修改:

def saveUser(self):
     name = self.fullname.get()
     email = self.email.get()
     marketing = self.optin.get()
     vehicle = self.vehicle_class.get()
     account_type = self.video.get()

     new_member = customer([fullname], email, accounttype, optin, self.video.get())
     DBfile = ".\\databaseeflow.mdb"
     conn = pypyodbc.connect(r"DRIVER={Microsoft Access Driver (*.mdb)};DBQ="+DBfile)
     cursor = conn.cursor()
     SQL = "INSERT INTO AccountList (ID, [fullName], email, optin, accounttype, vehicleclass) VALUES ('" 
     SQL = SQL + "Edin Gogic" + "','"
     SQL = SQL + "edingogic@itb.ie" + "','"
     SQL = SQL + "1" + "','"
     SQL = SQL + "video" + "','"
     SQL = SQL + "car" + "');"