February 2019
Beginner
136 pages
3h 7m
English
The DELETE operation is another operation that can be performed on a table. To do so, we shall pass a reference to the database connection and pass the DELETE statement to the exec() method of QSqlQuery.
Consider the following snippet:
// Delete a recordQSqlQuery delete_statement(db_conn);delete_statement.exec("DELETE FROM contacts WHERE first_name = 'Warrick'");qDebug() << "Number of rows affected: " << delete_statement.numRowsAffected();
numRowsAffected() is a method that is used to figure out how many records were affected. One benefit of this method is that it helps determine whether our query has changed the database. If it returns -1, it means that the query's operation produced indeterminate results.
Read now
Unlock full access