[Solved]Insert data and modify data of the database continuously



  • insert
    @
    QSqlQuery qry;

    qry.prepare("INSERT INTO komica_address (address, number) VALUES (?, ?)");
    std::for_each(std::begin(data), std::end(data), [&](std::pair<QString, int> const &value)
    {
      qry.addBindValue(value.first);
      qry.addBindValue(value.second);
      qry.exec&#40;&#41;;
    }&#41;;
    
    #ifdef DEBUG_OK
    qDebug() << qry.lastError();
    #endif
    

    @

    update
    @
    qry.prepare("UPDATE komca_address SET number = ? WHERE address = ?");
    std::for_each(std::begin(data), std::end(data), [&](std::pair<QString, int> const &value)
    {
    qry.addBindValue(value.second);
    qry.addBindValue(value.first);
    qry.exec();
    });
    @

    I have three questions :
    1 : Is this a correct solution to insert the data into the database continuously?

    2 : I can't update the value with the codes of "update"



  • [quote author="stereomatching" date="1346723020"]1 : Is this a correct solution to insert the data into the database continuously?[/quote]Yes.
    [quote author="stereomatching" date="1346723020"]2 : I can't update the value with the codes of "update"[/quote]Because your table is <code>komica_address</code>, not <code>komca_address</code>.
    [quote author="stereomatching" date="1346723020"]I have three questions :[/quote]No you don't.



  • [quote author="Lukas Geyer" date="1346734932"][quote author="stereomatching" date="1346723020"]1 : Is this a correct solution to insert the data into the database continuously?[/quote]Yes.
    [quote author="stereomatching" date="1346723020"]2 : I can't update the value with the codes of "update"[/quote]Because your table is <code>komica_address</code>, not <code>komca_address</code>.
    [quote author="stereomatching" date="1346723020"]I have three questions :[/quote]No you don't.[/quote]

    You just made my day. Instant classic.



  • Thanks, I think I should not coding and post the question when I was so tired.


Log in to reply
 

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