Hi, since you only query one "field" the index is 0. Thus you can simplify your code:
QSqlQuery q
("select count(MaDaiLy) from DaiLy, Quan where DaiLy.Quan_TenQuan = Quan.TenQuan and Quan.TenQuan = '" + ui.
cbTenQuan->currentText
() + "'");
q.next();
int SoDLHienCoTrongQuan = q.value(0).toInt();
QSqlQuery q("select count(MaDaiLy) from DaiLy, Quan where DaiLy.Quan_TenQuan = Quan.TenQuan and Quan.TenQuan = '" + ui.cbTenQuan->currentText() + "'");
q.next();
int SoDLHienCoTrongQuan = q.value(0).toInt();
To copy to clipboard, switch view to plain text mode
Further have a look at QSqlQuery::bindValue().
Bookmarks