首页 > 解决方案 > 发现很难将我的数据库与我的 gui 链接起来。全名未定义?

问题描述

试图将我的数据库与我的 GUI 链接到一个大学项目。我是 python 新手。我现在收到一个全名未定义错误。我知道它可能很简单。一个半小时后到期,所以我想我把它扔在这里看看会发生什么。提前谢谢各位。

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" + "');"

任何人都可以看到一个明显的问题吗?谢谢

标签: pythonms-access

解决方案


我找到了。缺少单引号。看看第一个条目中的引用是如何丢失的。它应该'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" + "');"

推荐阅读