How to reset DB table
Solved
General and Desktop
-
this is my code where inserting json data into db table
QJsonDocument doc = QJsonDocument::fromJson(data); QJsonArray array = doc.array(); QJsonObject object = array.at(0).toObject(); QString code = object["VillageCode"].toString(); qDebug()<< "VillageCode" +code; QString code1 = object["VillageName"].toString(); qDebug()<< "VillageName" +code1; QString code2 = object["RyotCode"].toString(); qDebug()<< "RyotCode" +code2; QString code3 = object["RyotName"].toString(); qDebug()<< "RyotName" +code3; QString code4 = object["SectionCode"].toString(); qDebug()<< "SectionCode" +code4; QString code5 = object["PhNo"].toString(); qDebug()<< "PhNo" +code5; QSqlQuery query; query.prepare("INSERT INTO farmer1 (VillageCode , VillageName, RyotCode, RyotName, SectionCode, PhNo) " "VALUES (:villageCode, :villageName, :ryotCode, :ryotName, :sectionCode, :phNo)"); query.bindValue(":villageCode", code); query.bindValue(":villageName", code1); query.bindValue(":ryotCode", code2); query.bindValue(":ryotName", code3); query.bindValue(":sectionCode", code4); query.bindValue(":phNo", code5); query.exec(); //QTableModel model2 = new QTableModel(this); QStringRef subString(§ioncode, 0, 10); qDebug()<< "Current Text"+ subString; QSqlTableModel* model2 = new QSqlTableModel(this); model2->setTable(QStringLiteral("farmer1")); model2->setFilter(("SectionCode ='"+subString+"'")); model2->select(); model2->setHeaderData (1,Qt::Horizontal, QObject::tr ("Ryot No.")); model2->setHeaderData (2,Qt::Horizontal, QObject::tr ("Ryot Name")); model2->setHeaderData (6,Qt::Horizontal, QObject::tr ("Mobile")); //ui->tableView->setEnabled(false); ui->tableView_2->setModel(model2); ui->tableView_2->hideColumn(0); ui->tableView_2->hideColumn(3); ui->tableView_2->hideColumn(4); ui->tableView_2->hideColumn(5);
so here i need to clear my DB table where the value is inserting repeatedly .
Help me out..!!! -
@Vineela
Hi
most such things you do via SQL
https://www.w3schools.com/sql/sql_drop_table.asp
(note, this also removes the table definition)
So you want next post. -
@Vineela "DELETE FROM farmer1" https://www.w3schools.com/sql/sql_delete.asp
-
@Vineela "DELETE FROM farmer1" https://www.w3schools.com/sql/sql_delete.asp