Add Row



  • Greeting,
    I'm new one here and i need some help in my project.
    Actually, I working on Cashed table and trying to change some things on it. But i face problem, When i trying to add new row in the table it not appear to me in the run program. I just get (4 rows ). So Please if anyone can advice me to how i can add more rows in this cashed table??
    @
    QSqlQuery query;

    query.exec("create table test (id int primary key, start text, last varchar(20),Degree varchar(20), ss int(3))");

    query.exec("insert into test values(1, 'Ta', 'Em','Bsc','2')");
    query.exec("insert into test values(2, 'Do', 'Yo','Bsc','3')");
    query.exec("insert into test values(3, 'Ah', 'Sa','Bsc','4')");
    query.exec("insert into test values(4, 'DR', 'Su','Phd','3')");
    query.exec("insert into test values(5, 'Sa', 'hh,'Bsc','3')");
    @
    if you see in the run only 4 rows appear ( 1 - 4) but the last one not appear.
    I will be Grateful for any help and advice

    Kind Regards,

    Fixed formatting for you. Please use @ tags around code sections; André



  • There is an error in the last statement. I have fixed the alignment of the code for you to make it obvious.

    Also, I think the create statement looks iffy. What are the semicolons doing in there?



  • Oh Thanks,

    Actually, I'm not sure if i understood you, But you mean i have problem in the Create Statement or What ??

    Kind Regarrds.



  • Looks like it, but your main issue is that your last insert query is faulty. You should get in the habbit of actually checking the return value of query.exec(), and using query.lastError() to get information on what wend wrong.



  • @QSqlQuery query;
    query.exec("create table test (id int primary key,"
    "startname text, lastname varchar(20),Degree varchar(20), ss int(3))");
    query.exec("insert into test values(1, 'Ta', 'Em','Bsc','2')");
    query.exec("insert into test values(2, 'Do', 'Yo','Bsc','3')");
    query.exec("insert into test values(3, 'Ah', 'Sa','Bsc','4')");
    query.exec("insert into test values(4, 'DR', 'Su','Phd','3')");
    query.exec("insert into test values(5, 'Sa', 'hh,'Bsc','3')");
    query.exec();
    query.lastError();@

    mmm the same, Please how i will can get information on what wend wrong

    Regards,



  • Again: closely compare your last two insert statements. Their (mis-) alignment gives you a very good hint what is going wrong.

    What is the result of your last query.exec() call? What does query.lastError() return?



  • OMG, I got it. I found the problem. It Was in the quotation.

    Thanks, Very much.

    but i have Question, If i used query.lastError() how it will return and where i can found this ??
    then what query.exec() will use ??

    Thanks



  • lastError will report on the most recently executed query.

    query.exec() already returns a boolean, so you could write:
    @
    if (!query.exec("insert into test values(5, 'Sa', 'hh,'Bsc','3')")) {
    qDebug() << query.lastError();
    }
    @



  • Well, Thanks So much


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.