增删改查

1、实现对MySql得数据库插入操作

1
2
3
4
5
6
7
QSqlQuery query(dbconn);
query.prepare("INSERT INTO faceimage(FaceData,StrName,Sijian,Shijian)" "VALUES(:FaceData,:StrName,:Sijian,:Shijian)");
query.bindValue(":FaceData",this->ui->ImageLabel->text());
query.bindValue(":StrName",this->ui->userName->text());
query.bindValue(":Sijian",this->ui->idNumber->text());
query.bindValue(":Shijian",Catchtime);
query.exec();

2、实现对MySql得数据库删除操作

1
2
3
4
QSqlQuery query(dbconn);
query.prepare(QString("DELETE FROM faceimage WHERE Faceid=?"));
query.addBindValue(Faceid);
query.exec();

3、实现对MySql得数据库得更新操作

1
2
3
4
5
query.prepare("update faceimage set StrName=?,Sijian=? where Faceid=?");
query.addBindValue(this->ui->XGuserName->text());
query.addBindValue(this->ui->XGidNumber->text());
query.addBindValue(Faceid);
query.exec();

4、实现对MySql数据库得遍历操作

1
2
3
4
5
6
7
8
9
10
 QSqlQuery query(dbconn);
query.prepare(sql);
while(query.next())
{
m_model->setItem(i,0,new QStandardItem(query.value(0).toString()));
m_model->setItem(i,1,new QStandardItem(query.value(3).toString()));
m_model->setItem(i,2,new QStandardItem(query.value(6).toString()));
m_model->setItem(i,3,new QStandardItem(query.value(2).toString()));
i++;
}