嗨,我想插入数据到sqlite数据没有插入。 错误消息
代码中的MY函数
def addstudent(self):
b2 = self.a2.text()
b3 = self.a3.text()
b4 = self.a4.text()
b5 = self.a5.text()
b6 = self.a6.text()
b7 = self.a7.text()
b8 = self.a8.text()
b9 = self.a9.itemText(self.a9.currentIndex())
b10 = self.a10.itemText(self.a10.currentIndex())
b11 = self.a11.itemText(self.a11.currentIndex())
b12 = self.a12.text()
b13 = self.a13.itemText(self.a13.currentIndex())
b14 = self.a14.itemText(self.a14.currentIndex())
b15 = self.a15.text()
b16 = self.a16.itemText(self.a16.currentIndex())
try:
conn = sqlite3.connect("collage_App.db")
dbs = conn.cursor()
dbs.execute("""INSERT INTO student_registration VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, , ?, ?) """ , (b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12,b13,b14,b15,b16, arrow.now().format('YYYY-MM-DD')) )
conn.commit()
conn.close()
QMessageBox.information(QMessageBox(),'Successful','Student is added successfully into database.')
self.close()
except Exception:
QMessageBox.warning(QMessageBox(), 'Error', 'Could not add student to the database.')
我的按钮事件代码
#Submit Button Clicked
self.add.clicked.connect(self.addstudent)
答案 0 :(得分:1)
您需要删除try-except子句并发布实际错误。
另一方面,使用Django处理数据库会更好。在https://www.djangoproject.com/start/中查看其教程。它不那么容易出错,并且为使用模型提供了一个很好的界面。