In the previous example, we wrote our very first SQL query, which involves the SELECT statement. This time, we will learn how to use some other SQL statements, such as INSERT, UPDATE, and DELETE.
Writing basic SQL queries
How to do it...
Let's create a simple program that demonstrates basic SQL query commands by following these steps:
- We can use our previous project files, but there are a couple of things we need to change. Open mainwindow.ui and replace the labels for Name and Age with line-edit widgets. Then, add three buttons to the canvas and call them UPDATE, INSERT, and DELETE:
- Open mainwindow.h and add the following variables under the private inheritance:
private:
Ui::MainWindow *ui;
QSqlDatabase db...