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. Problem in deleting data from the database?

Problem in deleting data from the database?

Scheduled Pinned Locked Moved General and Desktop
8 Posts 3 Posters 2.9k 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.
  • P Offline
    P Offline
    pratik041
    wrote on last edited by
    #1

    I am using the following query but the data is not deleting from the database.
    @
    qry.prepare("DELETE FROM name WHERE id = :id AND cus = :cus");
    qry.bindvalue(:id, id.text().toint());
    qry.bindvalue(:cus, cus.toplaintext());
    qry.exec();
    @

    Pratik Agrawal

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

      Most probably because this is neither valid SQL, nor valid C++.
      @
      qry.prepare("DELETE FROM name WHERE id = :id AND cus = :cus");
      qry.bindValue(":id", id->text().toInt());
      qry.bindValue(":cus", cus->toPlainText());
      qry.exec();
      @
      Make sure you've verfied that <code>id</code> and <code>cus</code> contain resonable values.

      And what has this to do in the Talk > Jobs section?

      1 Reply Last reply
      0
      • P Offline
        P Offline
        pratik041
        wrote on last edited by
        #3

        [quote author="Lukas Geyer" date="1326983394"]Most probably because this is neither valid SQL, nor valid C++.
        @
        qry.prepare("DELETE FROM name WHERE id = ':id' AND cus = ':cus'");
        qry.bindValue(":id", id->text().toInt());
        qry.bindValue(":cus", cus->toPlainText());
        qry.exec();
        @
        Make sure you've verfied that <code>id</code> and <code>cus</code> contain resonable values.

        And what has this to do in the Talk > Jobs section?[/quote]
        that is i have not noticed mistakenly i have posted in jobs section. Can you move it to desktop section?

        Pratik Agrawal

        1 Reply Last reply
        0
        • T Offline
          T Offline
          troubalex
          wrote on last edited by
          #4

          Done. :)

          THE CAKE IS A LIE
          Web Community Manager - Qt Development Frameworks

          1 Reply Last reply
          0
          • P Offline
            P Offline
            pratik041
            wrote on last edited by
            #5

            [quote author="Lukas Geyer" date="1326983394"]Most probably because this is neither valid SQL, nor valid C++.
            @
            qry.prepare("DELETE FROM name WHERE id = ':id' AND cus = ':cus'");
            qry.bindValue(":id", id->text().toInt());
            qry.bindValue(":cus", cus->toPlainText());
            qry.exec();
            @
            Make sure you've verfied that <code>id</code> and <code>cus</code> contain resonable values.

            [/quote]
            i have tried this but it was not working.

            Pratik Agrawal

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

              Try removing the quotes from the query.
              @
              qry.prepare("DELETE FROM name WHERE id = :id AND cus = :cus");
              @

              Is the database connection opened? See <code>QSqlDatabase::database().isOpen()</code>.
              Is there any error issued? See <code>qry.lastError().text()</code>, <code>qry.lastError().driverText()</code>.
              What does <code>qry.prepare(...)</code> return?
              Are the values bound correctly? See <code>qry.boundsValues()</code>.
              Is there even a dataset with the given <code>id</code> and <code>cus</code> that can be deleted?
              Do both, <code>id->text().toInt()</code> and <code>cus->toPlainText()</code>, contain reasonable values?

              1 Reply Last reply
              0
              • P Offline
                P Offline
                pratik041
                wrote on last edited by
                #7

                [quote author="Lukas Geyer" date="1327040840"]Try removing the quotes from the query.
                @
                qry.prepare("DELETE FROM name WHERE id = :id AND cus = :cus");
                @

                Is the database connection opened? See <code>QSqlDatabase::database().isOpen()</code>.
                Is there any error issued? See <code>qry.lastError().text()</code>, <code>qry.lastError().driverText()</code>.
                What does <code>qry.prepare(...)</code> return?
                Are the values bound correctly? See <code>qry.boundsValues()</code>.
                Is there even a dataset with the given <code>id</code> and <code>cus</code> that can be deleted?
                Do both, <code>id->text().toInt()</code> and <code>cus->toPlainText()</code>, contain reasonable values?[/quote]

                i have checked the code actually the deleting problem was coming only when i was using the function of QTableView
                @ QTableView::resizeRowtoContents()@
                I didn't understand why this was creating problem in deleting. Do you have any idea on that?

                Pratik Agrawal

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

                  [quote author="pratik041" date="1327142033"]I didn't understand why this was creating problem in deleting.[/quote]

                  Me neither.

                  Please add the things I've mentioned in my previous post to your code and try to find out what's actually the difference between those queries working and those queries not working.

                  And what does "not working" mean for you at all? Is there an error when the query is executed or is the query executed correctly and the record is just not removed?

                  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