RamrajCh
14th July 2019, 05:16
I tried to extract data from Amount column of my table and add all those and save them to string. But only first row is extracted,could anyone help?
Here is my codes:
QList<QString> Dbase_Cashier::getAmount()
{
QList<QString> amountdetails;
QSqlQuery qry;
qry.prepare(QString("SELECT Amount FROM Bill"));
if(!qry.exec())
{
qDebug()<<"Error in retriving data"<<qry.lastError();
}
else
{
if(qry.next())
{
QString i=qry.value(0).toString();
amountdetails.push_front(i);
}
else
{
qDebug()<<"not executing qyery";
}
}
qDebug()<<amountdetails.count();
return amountdetails;
}
And I have called above function as follows:
void CashierWindow::showAmount()
{
Dbase_Cashier db("SBS.db");
QList<QString> amountdetails=db.getAmount();
if(amountdetails.isEmpty())
{
qDebug()<<"empty";
}
else
{
qDebug()<<amountdetails.count();
}
}
Here,I got the console output as 1.
Here is my codes:
QList<QString> Dbase_Cashier::getAmount()
{
QList<QString> amountdetails;
QSqlQuery qry;
qry.prepare(QString("SELECT Amount FROM Bill"));
if(!qry.exec())
{
qDebug()<<"Error in retriving data"<<qry.lastError();
}
else
{
if(qry.next())
{
QString i=qry.value(0).toString();
amountdetails.push_front(i);
}
else
{
qDebug()<<"not executing qyery";
}
}
qDebug()<<amountdetails.count();
return amountdetails;
}
And I have called above function as follows:
void CashierWindow::showAmount()
{
Dbase_Cashier db("SBS.db");
QList<QString> amountdetails=db.getAmount();
if(amountdetails.isEmpty())
{
qDebug()<<"empty";
}
else
{
qDebug()<<amountdetails.count();
}
}
Here,I got the console output as 1.