PDA

View Full Version : unable to insert into mysql table



mohanakrishnan
4th December 2009, 12:21
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..


QSqlDatabase db1=QSqlDatabase::database("ganesh");
if(db1.open())
{
qDebug()<<"connection ok";
QSqlQuery query;
query.exec("insert into waitrequest(bednumber)values('123')");
}

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...:confused::crying:

JD2000
4th December 2009, 13:42
I think that the line should read

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

Lesiok
4th December 2009, 14:34
In line

QSqlDatabase db1=QSqlDatabase::database("ganesh");

You are getting database connection named "ganesh". And in line

QSqlQuery query;

You are using default database connection. Change this line to :

QSqlQuery query(db1);

mohanakrishnan
5th December 2009, 04:12
hi lesiok
thanks for ur help ,i ll try wat u said ,and come back
thanks...

mohanakrishnan
5th December 2009, 05:02
Hi Lesiok
thanks for ur help,it worked correctly,i was trying this for 3 hrs....
thanks a lot...
:D:D