Reputation: 14033
query->prepare("INSERT INTO businessweek (id, source, date, headline, body) VALUES (NULL, ?, ?, ?, ?)");
query->bindValue(1, "source");
query->bindValue(2, "date");
query->bindValue(3, "headline");
query->bindValue(4, "body");
if (query->exec()) {
tt << "Query success";
} else {
qDebug() << db.lastError();
return;
}
I'm using QMYSQL. And the error is
QSqlError(-1, "", "")
But
query->exec("INSERT INTO businessweek (id, source, date, headline, body) VALUES (NULL, 'google', 'may 0, 23', 'head', 'fjsdflksjdlkfdsjlfkjd');")
is working fine.
Upvotes: 3
Views: 1500
Reputation: 9157
It is hard to guess the problem. But one thing I could imagine and that definitely is wrong with your code is that field numbering for bindValue
starts at 0 (see here).
Thus, I would suggest to try
query->prepare("INSERT INTO businessweek (id, source, date, headline, body) VALUES (NULL, ?, ?, ?, ?)");
query->bindValue(0, "source");
query->bindValue(1, "date");
query->bindValue(2, "headline");
query->bindValue(3, "body");
if (query->exec()) {
tt << "Query success";
} else {
qDebug() << db.lastError();
return;
}
Upvotes: 3