當前位置:編程學習大全網 - 源碼下載 - QT數數據庫Mysql中 QSqlQuery、QSqlQueryModel 、和QSqlTableModel實現增刪改查?代碼

QT數數據庫Mysql中 QSqlQuery、QSqlQueryModel 、和QSqlTableModel實現增刪改查?代碼

用qsqltablemodel的insetrow()、setdata()、submitall()函數實現增;

officeTable->insertRow(0);

officeTable->setData(officeTable->index(0,?0),?row);

officeTable->setData(officeTable->index(0,?1),?newWnd->imageFileEditor->currentIndex());

officeTable->setData(officeTable->index(0,?2),?newWnd->locationText->text());

officeTable->setData(officeTable->index(0,?3),?newWnd->countryText->currentText());

officeTable->setData(officeTable->index(0,?4),?newWnd->descriptionEditor->toPlainText());

officeTable->submitAll();

用removerow()、submitall()函數實現刪;

int?officeCount?=?officeTable->rowCount();

officeTable->removeRow(id);

for(int?i?=?id;?i?<?officeCount?-?1;i++)

{

officeTable->setData(officeTable->index(i,?0),?i);

}

officeTable->submitAll();

用QSqlRecord類的setvalue實現改;

QSqlRecord?recordCurrentRow?=?officeTable->record(id);

recordCurrentRow.setValue("id",?id?-?1);

officeTable->setRecord(id?-?1,?recordCurrentRow);

officeTable->submitAll();

用QSqlRecord類的.value進行比較實現查;

int?Dialog::findArtistId(const?QString?&artist)

{

QSqlTableModel?*artistModel?=?model->relationModel(2);

int?row?=?0;

while?(row?<?artistModel->rowCount())?{

QSqlRecord?record?=?artistModel->record(row);

if?(record.value("artist")?==?artist)

return?record.value("id").toInt();

else

row++;

}

return?addNewArtist(artist);

}

  • 上一篇:恐怖的洗劫存款,新壹輪安全隱患來了!
  • 下一篇:《網易雲音樂》雲村治愈所使用方法
  • copyright 2024編程學習大全網