Results 1 to 4 of 4

Thread: Qsql bindValue issue

  1. #1
    Join Date
    May 2016
    Posts
    2
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Question Qsql bindValue issue

    Hi,

    My name is Kaan and I'm student. I writing a program and i was see an error. While i look generated SQL, i see blank SQL values. Please help me. (Sorry for my bad English.)

    My code is here:

    Qt Code:
    1. #include <QCoreApplication>
    2. #include <QDebug>
    3. #include <QSql>
    4. #include <QSqlQuery>
    5. #include <QSqlDatabase>
    6. #include <QSqlError>
    7.  
    8. int main(int argc, char *argv[])
    9. {
    10. QCoreApplication a(argc, argv);
    11. QSqlDatabase database = QSqlDatabase::addDatabase("QSQLITE");
    12. database.setDatabaseName("C:/Veritabani.db");
    13. database.open();
    14. qDebug() << database.lastError();
    15. QSqlQuery query;
    16. query.prepare("INSERT INTO Users(username, e_mail, password) VALUES(:username, :e_mail, :password)");
    17. query.bindValue(":username", "Kaan");
    18. query.bindValue(":e_mail", "kaansef@gmail.com");
    19. query.bindValue(":password", "123456");
    20. query.exec();
    21. qDebug() << query.executedQuery();
    22. return a.exec();
    23. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Qsql bindValue issue

    Does the database have a table calles "Users"?
    Have you tried with columns names that do not contain the underscore character?

    Cheers,
    _

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

    Default Re: Qsql bindValue issue

    Test what query.exec() returns. If false then print on qDebug() query.lastError().

  4. #4
    Join Date
    May 2016
    Posts
    2
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Qsql bindValue issue

    Thanks for replies. query.lastError() returns "Parameter count mismatch".

Similar Threads

  1. Replies: 0
    Last Post: 31st August 2014, 21:05
  2. QSqlQuery / bindValue syntax
    By dsant in forum Qt Programming
    Replies: 2
    Last Post: 27th April 2013, 14:29
  3. QSqlQuery::bindValue does not work
    By l0ud in forum Newbie
    Replies: 3
    Last Post: 23rd September 2012, 22:42
  4. QSqlQuery::bindValue
    By viglu in forum Newbie
    Replies: 3
    Last Post: 29th March 2010, 20:13
  5. QSqlQuery, bindValue and Sqlite
    By cydside in forum Qt Programming
    Replies: 4
    Last Post: 5th April 2009, 16:53

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.