I have the following code (it is a function), and I want to insert 500 values to my database whenever I call it.
QSqlDatabase::database().transaction();
query.prepare("INSERT INTO datatable (Name, age, data1, data2, data3, data4, data5)"
"VALUES (?, ?, ?, ?, ?, ?, ?)");
for (int i = 0; i<500; i++){
query.bindValue(0,Name[j]);
query.bindValue(1,age[j]);
query.bindValue(2,data1[j]);
query.bindValue(3,data2[j]);
query.bindValue(4,data3[j]);
query.bindValue(5,data4[j]);
query.bindValue(6,data5[j]);
query.next(); //just trying to go for the next row
}
qDebug() << "Finish" << QSqlDatabase::database().commit();
The problem is that this is only inserting the data from the values when j=500, I mean, this only stores the last data, and the other 499 doesn't get stored.
Can anyone help me? I have tried to put the query, prepared for loop inside but this didn't work as well.