How to take input date from user in qdateedit and show database accordingly
-
Can you post other parts of the code in relevance to this problem ?
-
Can you post other parts of the code in relevance to this problem ?
-
I am sorry for the partial code. Below is my actual code.
@login_page conn;
QString fill = ui->tableView->model()->data(index).toString();if(!conn.connopen())
{
qDebug()<<"Not connected";
return;
}conn.connopen(); QSqlQuery * qry = new QSqlQuery(); QSqlQuery * qry1 = new QSqlQuery(); QSqlQuery * qry2 = new QSqlQuery(); QSqlQuery * qry3 = new QSqlQuery(); qry->prepare("select * from instructor where i_id='"+fill+"' or i_name='"+fill+"'"); qry1->prepare("select gender from instructor where i_id='"+fill+"' or i_name='"+fill+"'"); qry2->prepare("select dob from instructor where i_id='"+fill+"' or i_name='"+fill+"'"); qry3->prepare("select yoga,martial_arts,aerobics,zumba,general,swimming,cardio,studio_cycel from instructor where i_id='"+fill+"' or i_name='"+fill+"'"); if(qry->exec() and qry1->exec() and qry2->exec() and qry3->exec()) { while(qry->next() and qry1->next() and qry2->next() and qry3->exec()) { QString str = qry1->value(0).toString(); //QString y,ma,a,z,g,s,sc,c; QString y = qry3->value(0).toString(); QString ma = qry3->value(1).toString(); QString a = qry3->value(2).toString(); QString z = qry3->value(3).toString(); QString g = qry3->value(4).toString(); QString s = qry3->value(5).toString(); QString c = qry3->value(6).toString(); QString sc = qry3->value(7).toString(); ui->txt_iid->setText(qry->value(0).toString()); ui->txt_iname->setText(qry->value(1).toString()); if((str == "male")) { ui->radioButton_male_2->setChecked(1); } else ui->radioButton_female_2->setChecked(1); if(y == "Yoga") { ui->checkBox_yoga->setChecked(1); } if(ma == "Martial arts") { ui->checkBox_ma->setChecked(1); } if((a == "Aerobics")) { ui->checkBox_a->setChecked(1); } if((z == "Zumba")) { ui->checkBox_z->setChecked(1); } if((g == "General")) { ui->checkBox_g->setChecked(1); } if((s == "Swimming")) { ui->checkBox_s->setChecked(1); } if((c == "Cardio")) { ui->checkBox_c->setChecked(1); } if((sc == "Studio cycle")) { ui->checkBox_sc->setChecked(1); } ui->txt_phone->setText(qry->value(12).toString()); ui->txt_street->setText(qry->value(13).toString()); ui->txt_apt->setText(qry->value(14).toString()); ui->txt_city->setText(qry->value(15).toString()); ui->txt_state->setText(qry->value(16).toString()); ui->txt_zip->setText(qry->value(17).toString()); conn.connclose(); } } else QMessageBox::information(this,tr("Error"),tr("Error in diaplaying")); @
-
I am sorry for the partial code. Below is my actual code.
@login_page conn;
QString fill = ui->tableView->model()->data(index).toString();if(!conn.connopen())
{
qDebug()<<"Not connected";
return;
}conn.connopen(); QSqlQuery * qry = new QSqlQuery(); QSqlQuery * qry1 = new QSqlQuery(); QSqlQuery * qry2 = new QSqlQuery(); QSqlQuery * qry3 = new QSqlQuery(); qry->prepare("select * from instructor where i_id='"+fill+"' or i_name='"+fill+"'"); qry1->prepare("select gender from instructor where i_id='"+fill+"' or i_name='"+fill+"'"); qry2->prepare("select dob from instructor where i_id='"+fill+"' or i_name='"+fill+"'"); qry3->prepare("select yoga,martial_arts,aerobics,zumba,general,swimming,cardio,studio_cycel from instructor where i_id='"+fill+"' or i_name='"+fill+"'"); if(qry->exec() and qry1->exec() and qry2->exec() and qry3->exec()) { while(qry->next() and qry1->next() and qry2->next() and qry3->exec()) { QString str = qry1->value(0).toString(); //QString y,ma,a,z,g,s,sc,c; QString y = qry3->value(0).toString(); QString ma = qry3->value(1).toString(); QString a = qry3->value(2).toString(); QString z = qry3->value(3).toString(); QString g = qry3->value(4).toString(); QString s = qry3->value(5).toString(); QString c = qry3->value(6).toString(); QString sc = qry3->value(7).toString(); ui->txt_iid->setText(qry->value(0).toString()); ui->txt_iname->setText(qry->value(1).toString()); if((str == "male")) { ui->radioButton_male_2->setChecked(1); } else ui->radioButton_female_2->setChecked(1); if(y == "Yoga") { ui->checkBox_yoga->setChecked(1); } if(ma == "Martial arts") { ui->checkBox_ma->setChecked(1); } if((a == "Aerobics")) { ui->checkBox_a->setChecked(1); } if((z == "Zumba")) { ui->checkBox_z->setChecked(1); } if((g == "General")) { ui->checkBox_g->setChecked(1); } if((s == "Swimming")) { ui->checkBox_s->setChecked(1); } if((c == "Cardio")) { ui->checkBox_c->setChecked(1); } if((sc == "Studio cycle")) { ui->checkBox_sc->setChecked(1); } ui->txt_phone->setText(qry->value(12).toString()); ui->txt_street->setText(qry->value(13).toString()); ui->txt_apt->setText(qry->value(14).toString()); ui->txt_city->setText(qry->value(15).toString()); ui->txt_state->setText(qry->value(16).toString()); ui->txt_zip->setText(qry->value(17).toString()); conn.connclose(); } } else QMessageBox::information(this,tr("Error"),tr("Error in diaplaying")); @
-
Sorry but the code looks little bit weird. I think you must first rectify them:
- No need to open the database twice.
- Since you are fetching everything from the same table with same where clauses why unnecessarily complicate the code by firing 4 different queries.
- Furthermore it complicates the if and while conditions.
- Closing the connection in while loop would be a bad idea as it will close the database and the end of first iteration itself and thus affecting the remaining data if any.
-
Sorry but the code looks little bit weird. I think you must first rectify them:
- No need to open the database twice.
- Since you are fetching everything from the same table with same where clauses why unnecessarily complicate the code by firing 4 different queries.
- Furthermore it complicates the if and while conditions.
- Closing the connection in while loop would be a bad idea as it will close the database and the end of first iteration itself and thus affecting the remaining data if any.