简体   繁体   English

如何使用 SQL 更新数据库 (MS Access .mdb) 中的数据

[英]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.

相关问题 如何更新从简单的SQL Server表中使用C ++中的ATL OLE数据库获取的行数据 - how to update row data fetched using ATL OLE database in C++ from simple SQL server table Windows 10中的MS Access数据库SQL查询问题 - MS Access database SQL query issue in windows 10 如何使用C ++获取MS Access数据库列的默认值? - How to get the default value of a column of MS Access Database using C++? 如何使用C ++将MS Access 2013数据库连接到Visual Studio 2013 - How to connect ms access 2013 database to visual studio 2013 using c++ 如何在不使用OLE DB API的情况下以C ++查询MS SQL Compact Server 3.5数据库? - How can I query a MS SQL Compact Server 3.5 database in C++ not using the OLE DB API? 如何使用WinApi从MS SQL表中检索大型二进制数据? - How to retrieve large binary data from MS SQL table using WinApi? 使用 C++ 将数据连接并插入到 MS Access 表中 - Connect and Insert data into a MS Access table using C++ 如何在未在C ++中安装ms office的系统中打开ms access数据库 - how to open ms access database in system which does not have ms office installed in c++ 如何获取访问mdb表的说明? (通过C ++) - how to get access mdb table description note ? (via c++) 使用Visual Studio 2008使用C ++连接到MS Access数据库 - Connecting to MS Access database using C++ using Visual Studio 2008
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM