Results 1 to 5 of 5

Thread: unable to insert into mysql table

  1. #1
    Join Date
    Oct 2009
    Location
    chennai,india
    Posts
    66
    Thanks
    18
    Qt products
    Qt4
    Platforms
    Windows

    Default unable to insert into mysql table

    hi
    im unable to insert a record into the table but im able to execute the select
    query..i checked ,the db connection is true..
    Qt Code:
    1. QSqlDatabase db1=QSqlDatabase::database("ganesh");
    2. if(db1.open())
    3. {
    4. qDebug()<<"connection ok";
    5. QSqlQuery query;
    6. query.exec("insert into waitrequest(bednumber)values('123')");
    7. }
    To copy to clipboard, switch view to plain text mode 
    but it shows message like below...
    QSqlQuery:: exec: database not open
    but if i use select query i get the result!!.
    any help is highly respected!!
    thanks...

  2. #2
    Join Date
    Oct 2009
    Posts
    151
    Thanks
    6
    Thanked 13 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: unable to insert into mysql table

    I think that the line should read

    query.exec("insert into waitrequest(bednumber)" "values('123')");

  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: unable to insert into mysql table

    In line
    Qt Code:
    1. QSqlDatabase db1=QSqlDatabase::database("ganesh");
    To copy to clipboard, switch view to plain text mode 
    You are getting database connection named "ganesh". And in line
    Qt Code:
    1. QSqlQuery query;
    To copy to clipboard, switch view to plain text mode 
    You are using default database connection. Change this line to :
    Qt Code:
    1. QSqlQuery query(db1);
    To copy to clipboard, switch view to plain text mode 

  4. The following user says thank you to Lesiok for this useful post:

    mohanakrishnan (5th December 2009)

  5. #4
    Join Date
    Oct 2009
    Location
    chennai,india
    Posts
    66
    Thanks
    18
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: unable to insert into mysql table

    hi lesiok
    thanks for ur help ,i ll try wat u said ,and come back
    thanks...

  6. #5
    Join Date
    Oct 2009
    Location
    chennai,india
    Posts
    66
    Thanks
    18
    Qt products
    Qt4
    Platforms
    Windows

    Smile unable to insert problem (fixed)

    Hi Lesiok
    thanks for ur help,it worked correctly,i was trying this for 3 hrs....
    thanks a lot...

Similar Threads

  1. unable to insert into table
    By mohanakrishnan in forum Qt Programming
    Replies: 0
    Last Post: 4th December 2009, 10:52
  2. Replies: 1
    Last Post: 16th July 2009, 02:25
  3. How to Compile VTKDesigner2 with Qt?
    By alfredoaal in forum Newbie
    Replies: 0
    Last Post: 5th September 2008, 05:34
  4. sort mysql table
    By eleanor in forum Qt Programming
    Replies: 2
    Last Post: 10th October 2007, 16:42
  5. MYSQL 5 Table qt model as small Mysql admin
    By patrik08 in forum Qt-based Software
    Replies: 0
    Last Post: 1st May 2007, 09:43

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.