python - 发现很难将我的数据库与我的 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" + "');"
任何人都可以看到一个明显的问题吗?谢谢
解决方案
我找到了。缺少单引号。看看第一个条目中的引用是如何丢失的。它应该'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" + "');"
推荐阅读
- sql - 仅获取行,直到达到 qty total
- android - 我的 Android 应用显示 Admob 插页式测试广告,但不是真实广告
- c++ - C++ 中的慢 std::vector vs [] - 为什么?
- python - 有没有办法在循环的每次迭代之后在 for 循环中产生“剩余迭代次数”计数?
- android - 在 Intent.createChooser() 中使用的 BroadcastReceiver 的参数
- c++ - 如何在 C++ 的循环中更改结构成员
- excel - 在 Excel 单元格中查找和替换特定文本
- javascript - 带有马丁内斯交集的传单:无效的 LatLng 对象:(-8.39,37.08,-8.39,37.08)
- azure - Azure AD B2C - 启用 MS 365 注册/登录
- nativescript - 将 NativeScript 应用程序从 3 升级到 7,有什么建议吗?