#include <QtCore>
#include <QtSql>
#include <QDebug>
int main(int argc, char *argv[])
{
db.setDatabaseName("test.db");
if (db.open()) {
// Create a test table
query.exec(
"create table clients ("
"id int, "
"ClientName VARCHAR(10),"
"ClientCity VARCHAR(10),"
"ClientAddress VARCHAR(10),"
"ClientMol VARCHAR(10),"
"ClientEik VARCHAR(10),"
"ClientVat VARCHAR(10),"
"ClientTel VARCHAR(10),"
"ClientMail VARCHAR(10) )" );
query.exec("insert into clients values(1, 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H')" );
query.exec("insert into clients values(2, 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H')" );
// Your Code
query.prepare("UPDATE clients SET "
"ClientName=:name, ClientCity=:city, ClientAddress=:address, ClientMol=:mol, "
"ClientEik=:eik, ClientVat=:vat, ClientTel=:tel, ClientMail=:mail WHERE id=:id");
query.bindValue(":name", "Z");
query.bindValue(":city", "Z") ;
query.bindValue(":address", "Z");
query.bindValue(":mol", "Z");
query.bindValue(":eik", "Z");
query.bindValue(":vat", "Z");
query.bindValue(":tel", "Z");
query.bindValue(":mail", "Z");
query.bindValue(":id", 1);
if (query.exec())
qDebug() << "Done OK";
else
qDebug() << "Huh!";
// Dump the table id and ClientName
query.exec("SELECT * FROM clients");
while (query.next()) {
qDebug() << query.value(0).toInt() << query.value(1).toString();
}
}
return 0;
}
#include <QtCore>
#include <QtSql>
#include <QDebug>
int main(int argc, char *argv[])
{
QCoreApplication app(argc, argv);
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
db.setDatabaseName("test.db");
if (db.open()) {
QSqlQuery query;
// Create a test table
query.exec(
"create table clients ("
"id int, "
"ClientName VARCHAR(10),"
"ClientCity VARCHAR(10),"
"ClientAddress VARCHAR(10),"
"ClientMol VARCHAR(10),"
"ClientEik VARCHAR(10),"
"ClientVat VARCHAR(10),"
"ClientTel VARCHAR(10),"
"ClientMail VARCHAR(10) )" );
query.exec("insert into clients values(1, 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H')" );
query.exec("insert into clients values(2, 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H')" );
// Your Code
query.prepare("UPDATE clients SET "
"ClientName=:name, ClientCity=:city, ClientAddress=:address, ClientMol=:mol, "
"ClientEik=:eik, ClientVat=:vat, ClientTel=:tel, ClientMail=:mail WHERE id=:id");
query.bindValue(":name", "Z");
query.bindValue(":city", "Z") ;
query.bindValue(":address", "Z");
query.bindValue(":mol", "Z");
query.bindValue(":eik", "Z");
query.bindValue(":vat", "Z");
query.bindValue(":tel", "Z");
query.bindValue(":mail", "Z");
query.bindValue(":id", 1);
if (query.exec())
qDebug() << "Done OK";
else
qDebug() << "Huh!";
// Dump the table id and ClientName
query.exec("SELECT * FROM clients");
while (query.next()) {
qDebug() << query.value(0).toInt() << query.value(1).toString();
}
}
return 0;
}
To copy to clipboard, switch view to plain text mode
Bookmarks