如何从数据库(SQLITE)将特定ID的数据添加到lineEdits

时间:2019-05-24 11:27:29

标签: qsqlquery

我想从数据库中获取数据并在lineEdits上进行设置以生成用户个人资料

void Home::on_profilePB_clicked()
{
    ui->stackedWidget->setCurrentIndex(5);
    QSqlQuery query;
    QString empID,firstname, lastname,empRole,CellNum,emailAddress,password,deptno,carRegistration;
    query.exec("SELECT empID,firstname, lastname,empRole,CellNum,emailAddress,password,deptno,carRegistration FROM employee WHERE empID='"+ui->empIdEdit->text()+"'");

    empID=query.value(0).toString();
    firstname=query.value(1).toString();
    lastname=query.value(2).toString();
    empRole=query.value(3).toString();

    CellNum=query.value(4).toString();
    emailAddress=query.value(5).toString();
    password=query.value(6).toString();
    deptno=query.value(7).toString();
    carRegistration=query.value(8).toString();

    ui->empIDShow->setText(empID);
    ui->lastNameEdit->setText(lastname);
    ui->firstnameEdit->setText(firstname);
    ui->contactNumEdit->setText(CellNum);

    ui->jobRole->setText(empRole);
    ui->emAdd->setText(emailAddress);

}

我收到此消息:

  

QSqlQuery :: value:不在有效记录上

0 个答案:

没有答案