Database forms

Contents



Overview


With HBasic you can edit the contents of a database table
This document will describe how to connect database columns within a form to lineedit widgets. We will call this special forms database form . You may create a new database form with the database form wizard or by inserting the needed components into an existing form.

When you have created a database form you can display and edit values from a selected table within lineedit components within the form. Every database forms needs a dbcursor widget which shows the buttons to select the current database row, create a new database row or delete the current row. You can move to the first, previous next or last database row within the table that has been connected to dbcursor component. With the other two buttons you can insert a new row into the table or delete the current row from the table.

database_form



Prerequisites


Before you can connect to database columns you have to


The database form wizard


To create a new  database with the wizard click on the New button in the menu or toolbar. This pops up a new dialog where you can select the type of the new structure that you want to create. Click on the DB-Form wizard icon to start the wizard. In the DB-Form wizard you can see a list of tables for the current project database. If the list is empty check your database connection parameter and if your database is online.

Select one of the tables from this list and click OK to start the generation of the new database form. The wizard will create a new form in your project with a db_cursor widget and a pair of  a Label widget and a LineEdit widget for each column in the table. The text of the Label widget will display the name of the column and the LineEdit widget will be connected to a column of the database table through the db_cursor widget.  

This form is ready to be used for editing database entries of the base-table of  the DB_CURSOR widget. Since this will not be the first form in your project you have to call the form.load() method within another form to start this form. You may for example set up a button button1 in your initial form and write a handler for the clicked event with the following code:


' load+open another form at runtime.

Sub button1_clicked()
   form2.load()
End Sub


For this example we assume that the name of the new created database form is form2.



Create a new database form without the wizard


If you want to set up a database form on your own start executing the following steps:

Open a new GUI form (click on new button and select the form icon).

Load the hbasic_dbaccess package (package editor) and reate a component of type db_cursor in your form. This component has a property which is called DB_TABLE of type string. Set the value of this property to the name of the database table which you want to use.

For each column that should be visible  in your form create a lineedit widget from the hbasic_stdgui package. This components has a property which is named DBCOLUMN. Insert the name of the database column that should be displayed in this lineedit component into this property.

If you now start the program the form should display the values of the database columns within your components. You can see an example image of a running data form at the top of this document. In the directory /usr/local/hbasic/code_examples you may find an example program with the name ex_db_form.bas which defines a database form for the table tab1 of the hbasic example database.