Results 1 to 8 of 8

Thread: SQL result problem

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Mar 2009
    Posts
    104
    Qt products
    Qt4
    Platforms
    MacOS X
    Thanked 1 Time in 1 Post

    Default Re: SQL result problem

    Thanks.Now it works!It was the wrong column.

  2. #2
    Join Date
    Mar 2009
    Posts
    104
    Qt products
    Qt4
    Platforms
    MacOS X
    Thanked 1 Time in 1 Post

    Default Re: SQL result problem

    Never deleted using this code:

    Qt Code:
    1. QModelIndexList selectedList = ui->tableView_clients->selectionModel()->selectedRows();
    2.  
    3. int selected_row;
    4. int i=0;
    5. selected_row=((selectedList.at(i).row())-1);
    6. QString row=QString::number(selected_row);
    7.  
    8. QSqlQuery query;
    9. query.prepare("DELETE from clients where ClientId="+row);
    10.  
    11. query.exec();
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,540
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanked 284 Times in 279 Posts

    Default Re: SQL result problem

    Try this :
    Qt Code:
    1. QModelIndexList selectedList = ui->tableView_clients->selectionModel()->selectedRows();
    2.  
    3. int selected_row;
    4. int i=0;
    5. selected_row=((selectedList.at(i).row())-1);
    6. QString row=QString::number(selected_row);
    7.  
    8. QSqlQuery query;
    9. QString my_query = QString("DELETE from clients where ClientId=")+row;
    10. query.prepare(my_query);
    11.  
    12. query.exec();
    To copy to clipboard, switch view to plain text mode 

    Look what You get in my_query after line 9 and think why.

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Wiki edits
    17

    Default Re: SQL result problem

    ... and be aware that the model row number and and the ClientID are not necessarily related to each other in any way.

    Why don't you use the model to QAbstractItemModel::removeRow() the selected item?

Similar Threads

  1. Replies: 2
    Last Post: 13th December 2011, 09:44
  2. How i can plot result in my GUI ?
    By 21did21 in forum Qwt
    Replies: 58
    Last Post: 18th June 2011, 01:41
  3. QRegExp - get only last result
    By kabanek in forum Newbie
    Replies: 2
    Last Post: 3rd November 2010, 23:17
  4. Replies: 4
    Last Post: 17th September 2010, 21:18
  5. How to display result
    By sksingh73 in forum Newbie
    Replies: 1
    Last Post: 7th June 2010, 09:39

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.