Results 1 to 2 of 2

Thread: Database and QSqlQuery::prepare problem

  1. #1
    Join Date
    Feb 2007
    Posts
    71
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Question Database and QSqlQuery::prepare problem

    mycode:

    Qt Code:
    1. void MainWindow::test()
    2. {
    3. QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
    4. db.setHostName("localhost");
    5. db.setDatabaseName("mytest");
    6. db.setUserName("root");
    7. db.setPassword("111111");
    8.  
    9. if (!db.open())
    10. {
    11. QMessageBox::information (this,"Database Error",db.lastError().text());
    12. }
    13. else
    14. {
    15. qDebug() << "Database OK";
    16. }
    17.  
    18. QSqlQuery *query=new QSqlQuery(db);
    19.  
    20. query->prepare("insert into testtable(t_data1,t_data2) value(?,?)");
    21. query->addBindValue(3);
    22. query->addBindValue(55);
    23. query->exec();
    24.  
    25. qDebug() << query->lastError().text();
    26. }
    To copy to clipboard, switch view to plain text mode 



    output :
    Database OK
    "Using unsupported buffer type: -842150451 (parameter: 2) QMYSQL3: Unable to bind value"



    database is not change. why???
    Last edited by jacek; 31st October 2007 at 23:14. Reason: changed [qtclass] to [code]

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Database and QSqlQuery::prepare problem

    What are the types of testtable fields?

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.