Hi,
I am trying toinsert multiple rows (you can actually call it records) in a database using QSqlTable model but cannot get it working. Can someone please help ?
Following is the code which works.
for(int i = 0 ; i < n; ++i){ // I want to insert some 10 rows
tableModel.select();
int rc = tableModel.rowCount();
tableModel.insertRow(rc);
rec = tableModel.record(rc);
tableModel.setRecord(rc,rec);
tableModel.submitAll();
}
for(int i = 0 ; i < n; ++i){ // I want to insert some 10 rows
tableModel.select();
int rc = tableModel.rowCount();
tableModel.insertRow(rc);
rec = tableModel.record(rc);
rec.setValue(QString("nameid"),QVariant(nameIds.at(i)));
rec.setValue(QString("groupid"),QVariant(currentGroupId));
tableModel.setRecord(rc,rec);
tableModel.submitAll();
}
To copy to clipboard, switch view to plain text mode
I have tired various other methods but all of them are failing. Can someone please suggest the best way to do this?
Thanks a lot.
Bookmarks