0

hi i want to insert into data into sqlite data doesn't insert. error message

enter image description here

MY function inside Code

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.')

My Button Event Code

#Submit Button Clicked
        self.add.clicked.connect(self.addstudent)
1
  • Welcome to SO! The error message you have posted is the error message you wrote in your own code. You are hiding the true error behind your own error handling. Remove the try/except block and you'll get a full stack trace with details of the real error. Commented Apr 10, 2020 at 6:52

1 Answer 1

1

You need to remove the try-except clauses and post the actual error.

On the other hand, you'd be better off using Django for working with Databases. Check their tutorial at https://www.djangoproject.com/start/. It's much less error-prone and provides a great interface for working with models.

Sign up to request clarification or add additional context in comments.

2 Comments

i have removed try catch now console error ** Exception "unhandled sqlite3.IntegrityError" datatype mismatch File: C:\Users\ultronhouse11\Documents\Eric6\collageApp\ui\Ui_registerStudent.py, Line: 729 **
It basically means that one of the data types that you've provided doesn't match what the database schema requires i.e. database requires "City" to be of type String while you've given it an Integer. You should name those fields differently than "a" or "b" as it will get very hard to find an error in your code later on.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.