int Sales::setmaxno()
{
QString sql
= "select max(billno) from tableSale";
query->prepare(sql);
if(query->exec() )
{
if(qury.next())
{
Sales::maxno = query->value(0).toInt();
return Sales::maxno;
}
}
else
{
QMessageBox::information(this,
"Sales",
"in else " + query
->lastError
().
text() );
}
}
int Sales::setmaxno()
{
QSqlQuery qury;
QString sql= "select max(billno) from tableSale";
query->prepare(sql);
if(query->exec() )
{
if(qury.next())
{
Sales::maxno = query->value(0).toInt();
return Sales::maxno;
}
}
else
{
QMessageBox::information(this, "Sales", "in else " + query->lastError().text() );
}
}
To copy to clipboard, switch view to plain text mode
The variable "qury" at line 3 and 9 is not related to the undeclared (member?) variable "query" at lines 6, 7, and 11. You prepare() and exec() one QSqlQuery object then attempt to navigate another (invalid) object. If that worked, you would return value from the first QSqlQuery object, which is pointing at an invalid record. Since "qury" is not active the next() call will fail and your code (if it compiles at all) will return an undefined value because there is no other return statement.
Bookmarks