QSqlQuery *query = new QSqlQuery(QSqlDatabase::database("myorg"));query->exec("create table myorg (id, name, fullname, yuradress, faktadress, inn, idbank, bankname, phone, pschet, direktor, kassir, glbuh)");query->exec("INSERT INTO myorg (id) VALUES ('1')");
QSqlQuery *queryMyOrg = new QSqlQuery(QSqlDatabase::database("myorg"));queryMyOrg->exec("SELECT * FROM myorg WHERE id='1'");queryMyOrg->first();ui.leName->setText(queryMyOrg->value(1).toString());ui.leFullName->setText(queryMyOrg->value(2).toString());ui.leYurAdress->setText(queryMyOrg->value(3).toString());ui.leFactAdress->setText(queryMyOrg->value(4).toString());ui.leInn->setText(queryMyOrg->value(5).toString());ui.lePhone->setText(queryMyOrg->value(8).toString());ui.leRSchet->setText(queryMyOrg->value(9).toString());ui.leLeader->setText(queryMyOrg->value(10).toString());ui.leAccountant->setText(queryMyOrg->value(12).toString());ui.leTeller->setText(queryMyOrg->value(11).toString());
QSqlQuery *queryMyOrg = new QSqlQuery(QSqlDatabase::database("myorg"));QString queryStr;queryStr = tr("UPDATE myorg SET name='%1', fullname='%2', yuradress='%3', faktadress='%4', inn='%5', idbank='%6', bankname='%7', phone='%8', pschet='%9', direktor='%10', kassir='%11', glbuh='%12' WHERE id='1'").arg(ui.leName->text()).arg(ui.leFullName->text()).arg(ui.leYurAdress->text()).arg(ui.leFactAdress->text()).arg(ui.leInn->text()).arg(QString::number(idBank)).arg(ui.cbBank->currentText()).arg(ui.lePhone->text()).arg(ui.leRSchet->text()).arg(ui.leLeader->text()).arg(ui.leTeller->text()).arg(ui.leAccountant->text());queryMyOrg->exec(queryStr);QMessageBox::critical(0, "", queryMyOrg->executedQuery());close();
{ QSqlQuery query(QSqlDatabase::database("myorg")); query.exec("create table myorg (id, name, fullname, yuradress, faktadress, inn, idbank, bankname, phone, pschet, direktor, kassir, glbuh)"); query.exec("INSERT INTO myorg (id) VALUES ('1')");}
int Count; QSqlRecord *buffer; QSqlCursor cPuskAG("test"); // таблица cPuskAG.select("countkey="+QString::numb(10)); // меняем запись №10 if (cPuskAG.next()==true) // есть запись { buffer = cPuskAG.primeUpdate(); // запись для обновления buffer->setValue("name","ales is ordnung"); Count=cPuskAG.update(); } if (Count==1) // запись успешна { }
C:\QT\3.3.8\examples\demo