//删除按钮对应的槽函数处理
void Widget::on_delBtn_clicked()
{
int numb=ui->numbEdit->text().toUInt();
if(numb==0)
{
QMessageBox::information(this,"","请输入要删除的学号");
return;
}
//准备sql语句
QSqlQuery query;
QString sql=QString("delete from stu_info_table where numb=%1").arg(numb);
//执行sql语句
if(!query.exec(sql))
{
QMessageBox::information(this,"","删除失败");
return;
}else {
QMessageBox::information(this,"","删除成功");
}
ui->tableWidget->clearContents();
on_showBtn_clicked();
}
//修改按钮对应的槽函数处理
void Widget::on_resBtn_clicked()
{
int numb=ui->numbEdit->text().toUInt();
QString name=ui->nameEdit->text();
QString sex=ui->sexEdit->text();
int score=ui->scoreEdit->text().toUInt();
QSqlQuery query;
if(!name.isEmpty())
{
QString sql=QString("update stu_info_table set name='%1' where numb=%2").arg(name).arg(numb);
query.exec(sql);
}
if(!sex.isEmpty())
{
QString sql=QString("update stu_info_table set sex='%1' where numb=%2").arg(sex).arg(numb);
query.exec(sql);
}
if(score!=0)
{
QString sql=QString("update stu_info_table set score=%1 where numb=%2").arg(score).arg(numb);
query.exec(sql);
}
on_showBtn_clicked();
}
?