Ejaz
Ejaz

Reputation: 1632

How to pass QLineEdit text to MS Access DB?

I am using the INSERT query, which works fine if I pass a string in the VALUES, like below:

oConn.Execute("Insert into Student_Info(Student_Name) values ('Robin')")

But I am getting an error if I pass the QLineEdit.text() this way:

oConn.Execute("Insert into Student_Info(Student_Name) values ('"& (self.StudentName.text()) &"')")

Error:

oConn.Execute("Insert into Student_Info(Student_Name) values ('"& (self.StudentName.text()) &"')")
TypeError: unsupported operand type(s) for &: 'str' and 'QString'

Please suggest, I am not sure what's wrong.

Upvotes: 0

Views: 79

Answers (1)

Bandhit Suksiri
Bandhit Suksiri

Reputation: 3460

Your can use python pass string easy way, like this;

command = '''Insert into Student_Info(Student_Name) values ('%s')''' % str(self.StudentName.text())
oConn.Execute(command)

Or your can use string concat;

command = "Insert into Student_Info(Student_Name) values ('" + str(self.StudentName.text()) + "')"
oConn.Execute(command)

Upvotes: 1

Related Questions