PDA

View Full Version : How to insert row to SQLite database?



MIH1406
20th May 2010, 14:47
Hi,

I am using SQLite database with QSqlTableModel and QDataWidgetMapper.

I want to insert a new row and save to the database file "database.db"

I have tried "insertRecord" and "insertRows" but I could not save the inserted row to the "database.db" file.

Any clue?

Thanks,
Mohammad

MIH1406
28th May 2010, 00:20
UP
How to insert row to SQLite database?

mecland
28th May 2010, 01:58
Using QT or SQLite3 client?

Mecland

jryannel
28th May 2010, 06:28
I would expect,



QSqlTableModel *model = ...
QSqlRecord record = model->record(); // get your template record from model
record.setValue(...);
model->insertRecord(-1, record); // append record at end
model->submitAll(); // depends on edit behaviour


This is untested code ;-)

MIH1406
28th May 2010, 09:23
Thank you I will try it.
I am using Qt

MIH1406
29th May 2010, 11:31
Hi jryanne,

I tried your code but it does not do anything? Any clue?

Thank you,
Mohammad

Naami
29th May 2010, 12:22
Hi;
try http://doc.trolltech.com/4.3/demos-sqlbrowser.html.