Search Logic
-
can any one help me with how to write logic to search button. Qt based one.. I have stored value in back end database. and showing the search in table view widget of my gui. how can i write query if user ender and searching any of these one field or h=
SELECT * FROM userdata WHERE (username LIKE '%' OR username LIKE 'Sam') AND (userrole LIKE 'Admin' OR userrole LIKE '%');
I have tried to retrieve like this, i know it'll give all the values in the data.how can i write query for this?!

-
QString nameField=ui->lineEdit_name->Text(); QString comboBoxRole=ui->comboBox_role->currentText(); QString salaryField=ui.lineEdit_salary->Text();Query:
SELECT * FROM userdata WHERE(username LIKE'"+nameFiled+"%' OR userrole LIKE '"+comboBoxRole+"%' OR salary LIKE'"+salaryField+"%' );you want like this ?
-
QString UserNameS=ui->SearchBox_Name->text();
QString UserRoleS = ui->SearchBox_Role->currentText();
QString UserSalaryS= ui->SearchBox_Salary->text();if (database.open()) { QMessageBox ::information(this,"Connection","Database is connected"); // QMessageBox::information(this,"Cnnected","connected"); this->model= new QSqlQueryModel(); QSqlQuery* qry1= new QSqlQuery(); qry1->prepare("SELECT * FROM userdata WHERE (username LIKE '%' OR username LIKE ':UserNameS') AND (userrole LIKE ':UserRoleS' OR userrole LIKE '%');"); //SELECT * FROM userdata WHERE username IN (:UserNameS,'') AND userrole IN (:UserRoleS,'')//SELECT * FROM userdata WHERE username IN (:UserNameS,'%') AND userrole LIKE (:UserRoleS,'%'); qry1->bindValue(":UserNameS",UserNameS); qry1->bindValue(":UserRoleS",UserRoleS); if (!qry1->exec()) { QMessageBox::information(this,"Failed","Query Not Executed"); }else { while(qry1->next()) { QString UserNameFromDb =qry1->value(1).toString(); QString UserRoleFromDb=qry1->value(2).toString(); if ((UserNameFromDb==UserNameS) || (UserRoleFromDb==UserRoleS) ) { // && (UserRoleFromDb==UserRoleS) //qry1->exec(); model->setQuery(*qry1); ui->SearchResult->setModel(model); }else { QMessageBox::information(this,"No User Found","No User Found in this name"); } }yes i want like this,but i dont know how to write query or logic for this