i am building small project, in Qt 5.7(on client) and mysql( on server). then in following program I stuck in "QMYSQLResult::data: column 1 out of range" problem. please help how to get rid of this.
void Sales
::on_comboBoxName_currentTextChanged(const QString &arg1
) {
QString sql
= "select productID, Rate, Stock from tableProductRecords where productname Like '%"+arg1
+ "%';";
query->prepare(sql);
if(query->exec(sql))
{
if(query->next())
{
ui->lineEditProductNumber->setText(query->value(0).toString().trimmed());
qDebug() << "ui->lineEditProductNumber->text().trimmed();" << ui->lineEditProductNumber->text().trimmed();
QString str1
= query
->value
(1).
toString().
trimmed();
ui->lineEditRate->setText(str1); // here is error of column out of range
qDebug() <<" ui->lineEditRate->text().trimmed(); " << ui->lineEditRate->text().trimmed();
QString str2
= query
->value
(2).
toString().
trimmed();
ui->lineEditStock->setText(str2);// here is error of column out of range
qDebug() <<"ui->lineEditStock->text().trimmed();" << ui->lineEditStock->text().trimmed();
}
}
}
void Sales::on_comboBoxName_currentTextChanged(const QString &arg1)
{
QString sql = "select productID, Rate, Stock from tableProductRecords where productname Like '%"+arg1+ "%';";
query->prepare(sql);
if(query->exec(sql))
{
if(query->next())
{
ui->lineEditProductNumber->setText(query->value(0).toString().trimmed());
qDebug() << "ui->lineEditProductNumber->text().trimmed();" << ui->lineEditProductNumber->text().trimmed();
QString str1 = query->value(1).toString().trimmed();
ui->lineEditRate->setText(str1); // here is error of column out of range
qDebug() <<" ui->lineEditRate->text().trimmed(); " << ui->lineEditRate->text().trimmed();
QString str2 = query->value(2).toString().trimmed();
ui->lineEditStock->setText(str2);// here is error of column out of range
qDebug() <<"ui->lineEditStock->text().trimmed();" << ui->lineEditStock->text().trimmed();
}
}
}
To copy to clipboard, switch view to plain text mode
output :-
ui->lineEditProductNumber->text().trimmed(); "1"
QMYSQLResult::data: column 1 out of range
ui->lineEditRate->text().trimmed(); ""
QMYSQLResult::data: column 2 out of range
ui->lineEditStock->text().trimmed(); ""
ui->lineEditProductNumber->text().trimmed(); "1"
ui->lineEditRate->text().trimmed(); "7000"
ui->lineEditStock->text().trimmed(); "4"
ui->lineEditProductNumber->text().trimmed(); "1"
QMYSQLResult::data: column 1 out of range
ui->lineEditRate->text().trimmed(); ""
QMYSQLResult::data: column 2 out of range
ui->lineEditStock->text().trimmed(); ""
ui->lineEditProductNumber->text().trimmed(); "1"
ui->lineEditRate->text().trimmed(); "7000"
ui->lineEditStock->text().trimmed(); "4"
To copy to clipboard, switch view to plain text mode
how do I get rid of "column out of range".
Bookmarks