hi. I have a code which is suppose to chec if the admission number being assigned to the new student is already assigned to another student. if already assigned, the system is to alert the user. i have this code but it is not working as required. what might be the problem?
QString admNum = admNumLineEdit->text();
QSqlDatabase db = QSqlDatabase::addDatabase(QMYSQL);
db.setHostName("localhost");
db.setDatabaseName("school");
db.setUserName("student");
db.setPassword("student");
QSqlQuery qeury;
if(!db.open())
{
....
}
else
{
query.prepare("SELECT adm FROM student_info WHERE adm = ':admission'");
query.bindValue(":admission", admNum);
if(!query.exec())
{
qDebug() << query.lastError();
}
else
{
QSqlRecord rec = query.record();
int cols = rec.count();
if(cols == 0)
{
QMessageBox::information(this, "admission number available", "Admission number can be assigned");
}
else
{
QMessageBox::information(this, "Invalid admission number", "Admission number already exist");
}
}
}
if I assign admNum to the same value as the one in the database or a different value, second qmessagebox is displayed. what can be the problem?
↧