关于qt 数据库的一个小问题
void Widget::on_pushButton_clicked()
{
qDebug()<< ui->lineEdit->displayText();
query.exec("INSERT INTO liubo (id, name) "
"VALUES (1001, 'Thad Beaumont')");
}
上面这段程序我先通过在lineedit 输入内容,然后点击按钮,把内容插入数据库中,但是不知道怎么写?
[解决办法]
QSqlQuery query;
query.prepare("INSERT INTO liubo (id, name) "
"VALUES (:id, :name)");
//或则query.prepare("INSERT INTO liubo VALUES (:id, :name)");
query.bindValue(":id", 1001);
query.bindValue(":name", ui->textEdit->text());
query.exec();