简体   繁体   中英

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.

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM