Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Solved]Insert data and modify data of the database continuously

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

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 1.8k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    stereomatching
    wrote on last edited by
    #1

    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"

    1 Reply Last reply
    0
    • L Offline
      L Offline
      lgeyer
      wrote on last edited by
      #2

      [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.

      1 Reply Last reply
      0
      • K Offline
        K Offline
        KA51O
        wrote on last edited by
        #3

        [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.

        1 Reply Last reply
        0
        • S Offline
          S Offline
          stereomatching
          wrote on last edited by
          #4

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

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved