数据库连接增多
作者:互联网
解决办法将验证去除例如
void db_data::showtb()
{
QDateTime startTime=ui.edit_startTime->dateTime();
QDateTime endTime=ui.edit_endTime->dateTime();
QString stime=ui.edit_startTime->dateTime().toString("yyyy-MM-dd");
QString etime=ui.edit_endTime->dateTime().toString("yyyy-MM-dd");
if(startTime>endTime)
{
QMessageBox::information(NULL, "查询错误", QString::fromLocal8Bit("查询出错,请重新选择时间"), QMessageBox::Yes);
return;
}
//if(!dbm->isConnect()) //如果数据库连接失败,直接返回
//{
// dbm->connectdb();
//}
int count=0;
QString sql1=QString("select count(*) from history_data where DATE_FORMAT(time, '%Y-%m-%d')>='%1' and DATE_FORMAT(time, '%Y-%m-%d')<='%2'").arg(stime).arg(etime);
QSqlQuery query1(sql1);
if(query1.exec())
{
while (query1.next()) {
count=query1.value(0).toInt();
}
}
ui.tableWidget->setRowCount(count);
QSqlQuery *query = new QSqlQuery;
QString sql=QString("select row_number() over(order by id) as ID,Hs,Hw,Hq,N1,N2,a1,a2,time from history_data where DATE_FORMAT(time, '%Y-%m-%d')>='%1' and DATE_FORMAT(time, '%Y-%m-%d')<='%2'").arg(stime).arg(etime);
query->prepare(sql);
if(!query->exec())
{
return;
}
int numb=0;
while (query->next()) {
ui.tableWidget->setItem(numb,0, new QTableWidgetItem(query->value(0).toString()));
ui.tableWidget->item(numb,0)->setTextAlignment(Qt::AlignCenter);
ui.tableWidget->setItem(numb,1, new QTableWidgetItem(query->value(1).toString()));
ui.tableWidget->setItem(numb,2, new QTableWidgetItem(query->value(2).toString()));
ui.tableWidget->setItem(numb,3, new QTableWidgetItem(query->value(3).toString()));
ui.tableWidget->setItem(numb,4, new QTableWidgetItem(query->value(4).toString()));
ui.tableWidget->setItem(numb,5, new QTableWidgetItem(query->value(5).toString()));
ui.tableWidget->setItem(numb,6, new QTableWidgetItem(query->value(6).toString()));
ui.tableWidget->setItem(numb,7, new QTableWidgetItem(query->value(7).toString()));
ui.tableWidget->setItem(numb,8, new QTableWidgetItem(query->value(8).toDateTime().toString("yyyy-MM-dd hh:mm:ss")));
numb++;
}
ui.tableWidget->selectRow(0);
//dbm->closedb();
}
将
//if(!dbm->isConnect()) //如果数据库连接失败,直接返回
//{
// dbm->connectdb();
//}
验证功能剔除。
标签:增多,toString,数据库,tableWidget,ui,numb,new,query,连接 来源: https://www.cnblogs.com/moon-mid-night/p/13937503.html