Qt15 Update a data from Sqlite database with pushbutton
来源:互联网 发布:锦江乐园门票 淘宝 编辑:程序博客网 时间:2024/06/03 18:20
1. reedit the employeeinfo window as
2. modify the employeeinfo.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()); }}
0 0
- Qt15 Update a data from Sqlite database with pushbutton
- QT16 delete data from sqlite database with pushbutton
- QT14 how to save data in sqlite database with pushbutton
- iPhone SDK Tutorial: Reading data from a SQLite Database
- HOW TO: Update a Database from a DataSet Object Us
- Lesson5 How to open a new window from a pushbutton
- clear test data from database;
- select data from another database
- use stack to initial a treeview with the data in a database
- Get all tables' name from sqlite database
- BDNtv: Deriving a model from an existing database with ECO II in Delphi 2005
- Extract lowercase masked FASTA from a BLAST database with masking information
- Creating a 10gr2 Data Guard Physical Standby database with Real-Time apply [ID 343424.1]
- Creating a 10gr2 Data Guard Physical Standby database with Real-Time apply [ID 343424.1]
- SQL: Update from a Select
- Generating XML Data from the Database
- Get Data from Database without definited Structure
- Working with the SQLite-Database - Cursors
- Callable与Runnable区别
- BAT执行PHP文件(区别于上一篇)
- Thread详解11:ThreadLocal的使用
- RecyclerView
- Java字符串详解
- Qt15 Update a data from Sqlite database with pushbutton
- 让BAT静静的执行(隐藏CMD界面)
- 227. Basic Calculator II
- linux环境变量
- FlyProgressView——仿Windows进度条
- Android开发之触摸事件处理机制详解
- BAT MYSQL BACKUP AND ARCHIVE WITH WINRAR
- mac下修改环境变量
- QT16 delete data from sqlite database with pushbutton