PDA

View Full Version : QMYSQLResult::data: column 1 out of range



rahulvishwakarma
5th June 2020, 12:05
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());
}
}


error is that when i run this code this shows two errors :-



QMYSQLResult::data: column 1 out of range

and :-
not enough space even if here is stock is10;

1346213463

how to recover this.

ChrisW67
6th June 2020, 04:18
Do clean rebuild of your project.
Single-step through this with your debugger and look at all the values concerned and which line triggers the message.