这是我的表:
CREATE TABLE IF NOT EXISTS CauHoi( MaCH VARCHAR(10) CHARACTER SET utf8 COLLATE utf8_unicode_ci PRIMARY KEY, MaMH VARCHAR(10) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL, Question TEXT CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL, Difficulty VARCHAR(10) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL, a TEXT CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL, b TEXT CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL, c TEXT CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL, d TEXT CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL, Answer VARCHAR(10) NOT NULL);
这是我的疑问:
answerComboBox->addItem("a");
answerComboBox->addItem("b");
answerComboBox->addItem("c");
answerComboBox->addItem("d");
q.prepare("INSERT INTO CauHoi(MaCH,MaMH,Question,Difficulty,a,b,c,d,Answer) VALUES ('"
+ maCHLineEdit->text() + "','"
+ maMHLineEdit->text() + "','"
+ questionTextEdit->toPlainText() + "','"
+ difficultyComboBox->currentText()+ "','"
+ aLineEdit->text() + "','"
+ bLineEdit->text() + "','"
+ cLineEdit->text() + "','"
+ dLineEdit->text() + "',"
+ answerComboBox->currentText()+");");
但是当q.exec(),如果answerComboBox-> currentText()==“c”时,CauHoi表中的Answer列变为cLineEdit-> text()。真是太疯狂了!我只想简单地说“a”,“b”,“c”,“d”。
请帮帮我
答案 0 :(得分:0)
我找到了。我在answerComboBox-> currentText()附近缺少单引号。
答案 1 :(得分:0)
您需要在
周围添加开头和结尾的单引号answerComboBox->currentText()