hi to all, I've centos 7 in VM qt 5.7. i am trying to buid a small project, in this i am connecting to mysql database.
i've this code :-
void Sales::on_lineEditQuantity_editingFinished()
{
quantity = ui->lineEditQuantity->text().trimmed().toInt();
int prdnumber = ui->lineEditProductNumber->text().trimmed().toInt();
QString sql
= "select rate,stock from tableProductRecords where productID = "+QString::number(prdnumber
) +";";
query->prepare(sql);
Sales::maxno = setmaxno();
if(query->exec())
{
if(query->next())
{
ui->lineEditRate->setText(query->value(0).toString().trimmed());
ui
->lineEditBillNo
->setText
(QString::number(Sales
::maxno));
ui
->lineEditTotal
->setText
(QString::number((query
->value
(0).
toInt()) * quantity
));
int st = query->value(1).toInt();
int stk = st - quantity;//ui->lineEditQuantity->text().trimmed().toInt();
if (stk <= 0)
{
ui->lineEditRate->setText("");
ui->lineEditBillNo->setText("");
ui->lineEditTotal->setText("");
QMessageBox::critical(this,
"Sales",
"Not enough stock\n available only " + QString::number(st
));
return;
}
else
{
ui
->lineEditStock
->setText
(QString::number(stk
));
sql
= "update tableProductRecords set stock = "+ QString::number(stk
) + " "+ "where productID = "+ ui
->lineEditProductNumber
->text
().
trimmed()+";";
query->prepare(sql);
if(query->exec())
{
QMessageBox::information(this,
"Salas",
"record updated");
}
}
}
else
{
QMessageBox::critical(this,
"on_lineEditQuantity_editingFinished",
"Error : " + query
->lastError
().
text());
}
}
else
{
QMessageBox::critical(this,
"on_lineEditQuantity_editingFinished",
"Error : " + query
->lastError
().
text());
}
}
void Sales::on_lineEditQuantity_editingFinished()
{
quantity = ui->lineEditQuantity->text().trimmed().toInt();
int prdnumber = ui->lineEditProductNumber->text().trimmed().toInt();
QString sql = "select rate,stock from tableProductRecords where productID = "+QString::number(prdnumber) +";";
query->prepare(sql);
Sales::maxno = setmaxno();
if(query->exec())
{
if(query->next())
{
ui->lineEditRate->setText(query->value(0).toString().trimmed());
ui->lineEditBillNo->setText(QString::number(Sales::maxno));
ui->lineEditTotal->setText(QString::number((query->value(0).toInt()) * quantity));
int st = query->value(1).toInt();
int stk = st - quantity;//ui->lineEditQuantity->text().trimmed().toInt();
if (stk <= 0)
{
ui->lineEditRate->setText("");
ui->lineEditBillNo->setText("");
ui->lineEditTotal->setText("");
QMessageBox::critical(this, "Sales", "Not enough stock\n available only " + QString::number(st));
return;
}
else
{
ui->lineEditStock->setText(QString::number(stk));
sql = "update tableProductRecords set stock = "+ QString::number(stk) + " "+ "where productID = "+ ui->lineEditProductNumber->text().trimmed()+";";
query->prepare(sql);
if(query->exec())
{
QMessageBox::information(this, "Salas", "record updated");
}
}
}
else
{
QMessageBox::critical(this, "on_lineEditQuantity_editingFinished","Error : " + query->lastError().text());
}
}
else
{
QMessageBox::critical(this, "on_lineEditQuantity_editingFinished","Error : " + query->lastError().text());
}
}
To copy to clipboard, switch view to plain text mode
error is that when i run this code this shows two errors :-
QMYSQLResult::data: column 1 out of range
QMYSQLResult::data: column 1 out of range
To copy to clipboard, switch view to plain text mode
and :-
not enough space even if here is stock is10;
not enough space.jpgdatabase.jpg
how to recover this.
Bookmarks