QT20 database values in QLineEdit or textbox if select combobox
来源:互联网 发布:stm32f103tbu6编程 编辑:程序博客网 时间:2024/06/07 01:30
1.modify employeeinfo window
2. modify employee.cpp
#include "employeeinfo.h"#include "ui_employeeinfo.h"#include "login.h"#include <QMessageBox>EmployeeInfo::EmployeeInfo(QWidget *parent) : QDialog(parent), ui(new Ui::EmployeeInfo){ ui->setupUi(this); if(!login::connOpen()) { ui->label_sec_status->setText("Failed to open the database") ; } else { ui->label_sec_status->setText("Connected...") ; }}EmployeeInfo::~EmployeeInfo(){ delete ui;}void EmployeeInfo::on_pushButton_clicked(){ QString eid, name, surname, age; eid = ui->txt_eid->text(); name =ui->txt_name->text(); surname = ui->txt_surname->text(); age = ui->txt_age->text(); if(!login::connOpen()) { qDebug() << "Failed to open the database"; return ; } QSqlQuery qry; QString stmt = "insert into employeeinfo (eid,name,surname,age) values('"+ eid +"','"+ name +"','"+ surname +"','"+ age +"')"; qry.prepare(stmt); if( qry.exec()) { QMessageBox::information(this, tr("Save"), tr("Saved")); login::connClose(); } else { QMessageBox::critical(this, tr("Error"), qry.lastError().text()); }}void EmployeeInfo::on_pushButton_edit_clicked(){ QString eid, name, surname, age; eid = ui->txt_eid->text(); name =ui->txt_name->text(); surname = ui->txt_surname->text(); age = ui->txt_age->text(); if(!login::connOpen()) { qDebug() << "Failed to open the database"; return ; } QSqlQuery qry; QString stmt = "update employeeinfo set eid='"+ eid+"',name='"+ name+ "',surname='"+ surname+"',age='"+ age +"'where eid='" + eid + "'"; qry.prepare(stmt); if( qry.exec()) { QMessageBox::information(this, tr("Edit"), tr("Updated")); login::connClose(); } else { QMessageBox::critical(this, tr("Error"), qry.lastError().text()); }}void EmployeeInfo::on_pushButton_delete_clicked(){ QString eid, name, surname, age; eid = ui->txt_eid->text();// name =ui->txt_name->text();// surname = ui->txt_surname->text();// age = ui->txt_age->text(); if(!login::connOpen()) { qDebug() << "Failed to open the database"; return ; } QSqlQuery qry; QString stmt = "delete from employeeinfo where eid = '"+ eid +"'"; qry.prepare(stmt); if( qry.exec()) { QMessageBox::information(this, tr("Delete"), tr("Deleted")); login::connClose(); } else { QMessageBox::critical(this, tr("Error"), qry.lastError().text()); }}void EmployeeInfo::on_pushButton_load_clicked(){ QSqlQueryModel * modal = new QSqlQueryModel(); login::connOpen(); QSqlQuery* qry = new QSqlQuery(login::mydb); QString stmt; stmt = "select name from employeeinfo"; qry->prepare(stmt); qry->exec(); modal->setQuery(*qry); ui->tableView->setModel(modal); ui->listView->setModel(modal); ui->comboBox->setModel(modal); login::connClose(); qDebug() << modal->rowCount();}void EmployeeInfo::on_comboBox_currentIndexChanged(const QString &arg1){ QString name = ui->comboBox->currentText(); if( !login::connOpen()) { qDebug() << "Failed to open the database"; return; } QSqlQuery qry; QString stsm = "select * from employeeinfo where name = '"+ name +"'"; qry.prepare(stsm); if( qry.exec()) { while(qry.next()) { ui->txt_eid->setText(qry.value(0).toString()); ui->txt_name->setText(qry.value(1).toString()); ui->txt_surname->setText(qry.value(2).toString()); ui->txt_age->setText(qry.value(3).toString()); } login::connClose(); } else { QMessageBox::critical(this, tr("Error"), qry.lastError().text()); }}
0 0
- QT20 database values in QLineEdit or textbox if select combobox
- QT22 database values in QLineEdit or textbox if select QListView
- Check if a table or field exists in a database
- select in or jion
- system setting manager, save or get system values from database
- ypcat - print values of all keys in a NIS database
- OBIEE Tips #5: Too many values in single select prompt
- How to display column values in a single cell in Web Intelligence using Oracle database ?
- INSERT小记(insert into select和not in,values括号里不能放select)
- Creating a Stored Procedure or Function in an Oracle Database
- 锁定TextBox,ComboBox的方法
- FIELD - VALUES, SELECT
- Sybase You can't run SELECT INTO in this database. Please check with the Database Owner.
- Check if a database and tables exist in sql server in a vb .net project
- QLineEdit
- QLineEdit
- QLineEdit
- QLineEdit
- 可能你不知道的TClientDataset功能
- QT19 How to link QComboBox with sqlite Database values
- java android中对list的时间进行排序
- 利用 Behavior Driven Development 技术加强软件自动化测试
- 客户端到服务器端的通信过程及原理
- QT20 database values in QLineEdit or textbox if select combobox
- Thread详解12:InheritableThreadLocal的使用
- 视频播放器(四)——总结篇
- Block的深入研究之Block的内存管理
- 71. Simplify Path
- Java异常处理
- 有趣的数 算法的题解(数位DP问题)
- QT21 Display selected row from QTableView to QlineEdit
- [hdu5654 xiaoxin and his watermelon candy]区间内不同数的个数