Not directly using the name and field name in the code
Create a mapping table, the name of the name and field of the table is set to a constant, and the corresponding table and field are operated in the code by reference to these constants. This allows if the table structure or field name is changed, just modify the mapping table.
Database connection is set to public variables
A common variable can be set to store a connection to the database. The form still contains its own connection variable, and only the value of the public variable (actually pointing to the pointer to the connection object) can be assigned to the form.
The benefits of this structure are:
* No need to check the status of the database connection repeatedly. Just open the connection when the program is running, it is possible to close the connection at the end of the program.
* The connection object is retained for each form, which is convenient for individual debugging of each form.
Disadvantages of this structure:
*
Not suitable for network environments with poor connectivity, such as operations of remote databases, and more.