SQL query not working
-
QSqlQuery a; QString b; a.exec("Select Stock From Manufacturer_stock Where Product=Parle"); if (a.next()) { b = a.value(0).toString(); ui->label_2->setText(b); }
This code does nothing. What is wrong?
-
Hi
The syntax is not valid i think
a.exec("Select Stock From Manufacturer_stock Where Product='Parle' ");
( add single quotes around text values )If you are using SQLite then
http://sqlitebrowser.org/
Is nice tools as you can test your SQL there and easy work with the database. -
I am using Access and the code is swill not working
i tried with quotes
i dont know whats wrong. All other queries are working fine. -
@ronyNS
Well are you sure it will get any hits then?
and Column is called Stock ? -
Yes i cross checked everything . Everything is perfect
-
You can try
a.exec("Select Stock From Manufacturer_stock Where Product like 'P%' ");And see if it matches Parla.
Else i am out of guesses. Did Not use Access since 1997 :)
-
-
I believe that the SQL standard requires a trailing semicolon (;) but some databases/drivers choke on it. Try
a.exec("Select Stock From Manufacturer_stock Where Product='Parle';");
Mike
-
HI
Can u try with this, hope this works for you.
QSqlQuery query; query.prepare("Select Stock From Manufacturer_stock Where Product='Parle'; "); query.exec(); while(query.next()) { QString firstValue = query.value(0).toString(); qDebug() << "first value :" << firstValue << endl; QString secondValue = query.value(1).toString(); qDebug() << "second value :" << secondValue << endl; }
and provide debug statements,
As mentioned by @p3c0 check whether the dB is opened. -
Hi!
You should get the error-message as already mentioned above:
QSqlQuery a; if( !a.exec("Select Stock From Manufacturer_stock Where Product='Parle';") ) { qDebug() << "Error:" << a.lastError().text(); }
10/10