[英]How to UPDATE data in database (MS Access .mdb) by using SQL
I want to update data in database (MS Access .mdb) by using SQL in QT Creator C++, but nothing happens.我想通过在 QT Creator C++ 中使用 SQL 更新数据库(MS Access .mdb)中的数据,但没有任何反应。
I tried to google this, but still nothing.我试图谷歌这个,但仍然没有。
void Chairs::on_pushButton_clicked()
{
mDatabase = QSqlDatabase::addDatabase("QODBC");
mDatabase.setDatabaseName(ACCESS);
if(!mDatabase.open())
{
QMessageBox::critical(this, "Error",
mDatabase.lastError().text());
return;
}
int quantity_of_chairs = 14;
int value = 1;
for (int i = 0; i < quantity_of_chairs; i++)
{
if(ui->comboBox->currentText() == value)
{
QSqlQueryModel *setquery1 = new QSqlQueryModel;
setquery1->setQuery("UPDATE Chairs SET Status = 'Ordered'
WHERE number_of_chair = "+value);
QTableView *tv = new QTableView(this);
tv->setModel(setquery1);
ui->tableView->setModel(setquery1);
}
value++;
}
}
QSqlDatabasePrivate::removeDatabase: connection 'qt_sql_default_connection' is still in use, all queries will cease to work. QSqlDatabasePrivate::removeDatabase: connection 'qt_sql_default_connection' 仍在使用中,所有查询将停止工作。 QSqlDatabasePrivate::addDatabase: duplicate connection name 'qt_sql_default_connection', old connection removed. QSqlDatabasePrivate::addDatabase:重复的连接名称“qt_sql_default_connection”,旧的连接被移除。
The answer is quite old, but having had the same problem myself, I found a solution (not necessarily the most optimized one, certainly) that I found on no subject.答案已经很老了,但是我自己也遇到了同样的问题,我找到了一个我没有找到的解决方案(当然不一定是最优化的)。
This message appears because you are trying to connect more than one on the same connection (the default one)出现此消息是因为您尝试在同一连接上连接多个(默认连接)
You just have to change the default name of the connection every time you want to make a new connection like this for yours mDatabase.defaultConnection="a_name_for_connection";
每次您想为您的mDatabase.defaultConnection="a_name_for_connection";
建立这样的新连接时,您只需要更改连接的默认名称mDatabase.defaultConnection="a_name_for_connection";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.