如何将QLineEdit文本传递给MS Access DB?

2024-03-29 05:38:52 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用的是INSERT查询,如果我在值中传递一个字符串,它可以正常工作,如下所示:

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

但是如果我通过了考试,我就错了QLineEdit.text文件()这样:

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

错误:

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

请告诉我,我不知道怎么了。你知道吗


Tags: 字符串textnameselfinfoexecutestudentrobin
1条回答
网友
1楼 · 发布于 2024-03-29 05:38:52

你可以用python传递字符串的简单方法,像这样

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

或者您可以使用字符串concat

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

相关问题 更多 >