arpspatel
9th April 2010, 02:02
Hi,
QString QueryDatabase(QString _query){
QSqlDatabase db = QSqlDatabase::addDatabase(type); //Available Types QMYSQL, QPSQL and QSQLITE
db.setDatabaseName(name);
db.setHostName(host);
if(!db.open(user,pass)){
return -1;
}
QSqlQuery query;
query.exec(_query);
QString result = query.result(); //How do i do this part
db.close();
return result;
}
I want to query the database with string like "select count(*)....." and the return value will always be in one row as its just counting the number of occurances.. how can i get the result direct of the row to QString??
Thanks
QString QueryDatabase(QString _query){
QSqlDatabase db = QSqlDatabase::addDatabase(type); //Available Types QMYSQL, QPSQL and QSQLITE
db.setDatabaseName(name);
db.setHostName(host);
if(!db.open(user,pass)){
return -1;
}
QSqlQuery query;
query.exec(_query);
QString result = query.result(); //How do i do this part
db.close();
return result;
}
I want to query the database with string like "select count(*)....." and the return value will always be in one row as its just counting the number of occurances.. how can i get the result direct of the row to QString??
Thanks