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;
qry.
prepare(QString("SELECT Amount FROM Bill"));
if(!qry.exec())
{
qDebug()<<"Error in retriving data"<<qry.lastError();
}
else
{
if(qry.next())
{
amountdetails.push_front(i);
}
else
{
qDebug()<<"not executing qyery";
}
}
qDebug()<<amountdetails.count();
return amountdetails;
}
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;
}
To copy to clipboard, switch view to plain text mode
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();
}
}
void CashierWindow::showAmount()
{
Dbase_Cashier db("SBS.db");
QList<QString> amountdetails=db.getAmount();
if(amountdetails.isEmpty())
{
qDebug()<<"empty";
}
else
{
qDebug()<<amountdetails.count();
}
}
To copy to clipboard, switch view to plain text mode
Here,I got the console output as 1.
Bookmarks