aniqbear
4th December 2016, 11:35
Hi,
I am new to the programming world,
I have trouble in finding a way to put the value of the Combobox into my database.
here's my coding. it is miserable.
void background::on_pushButton_3_clicked()
{
QString name, age,/*gender, pregnant,*/ weight, height/* family*/;
name=ui->lineEdit_name->text();
age=ui->lineEdit_age->text();
QString gender=ui->comboBox_gender->currentText();
QString pregnant=ui->comboBox_pregnant->currentText();
weight=ui->lineEdit_weight->text();
height=ui->lineEdit_height->text();
QString family=ui->comboBox_family->currentText();
QSqlQuery myqry;
myqry.prepare("INSERT INTO background(Name, Age, Gender, Pregnant, Weight, Height, Family) values('"+name+"','"+age+"','"+gender+"','"+pregnant+"','"+weight+"','"+height+"','"+family+"')");
if(myqry.exec()){
ui->labelstat->setText("The information has been saved");
// QMessageBox::information(this, "Save", "The information has been saved");
}
else{
ui->labelstat->setText("Information failed to saved");
// QMessageBox::warning(this, "Failed", "Information failed to saved");
}
}
I am new to the programming world,
I have trouble in finding a way to put the value of the Combobox into my database.
here's my coding. it is miserable.
void background::on_pushButton_3_clicked()
{
QString name, age,/*gender, pregnant,*/ weight, height/* family*/;
name=ui->lineEdit_name->text();
age=ui->lineEdit_age->text();
QString gender=ui->comboBox_gender->currentText();
QString pregnant=ui->comboBox_pregnant->currentText();
weight=ui->lineEdit_weight->text();
height=ui->lineEdit_height->text();
QString family=ui->comboBox_family->currentText();
QSqlQuery myqry;
myqry.prepare("INSERT INTO background(Name, Age, Gender, Pregnant, Weight, Height, Family) values('"+name+"','"+age+"','"+gender+"','"+pregnant+"','"+weight+"','"+height+"','"+family+"')");
if(myqry.exec()){
ui->labelstat->setText("The information has been saved");
// QMessageBox::information(this, "Save", "The information has been saved");
}
else{
ui->labelstat->setText("Information failed to saved");
// QMessageBox::warning(this, "Failed", "Information failed to saved");
}
}