Creating a database: – Before using a database on the form we must create a database. This database work as DAO. This database work similar to Microsoft access. It contains number of data field such as text, memo, number, date/time, currency, auto number, logical and OLE Object.
Visual data manager, application that is included with visual basic allow us to create database. To open and create a database with visual data manager, follow the following step –
- Start visual basic and click add-Ins on the menu bar. A list of menus option appears, select visual data manager.
- A visual data manager window will open. Click file on the menu bar, then click new on the file menu. A sub menu opens. Click Microsoft access. Another sub menu opens. Click version 7.0 MDB. The select Microsoft access database to create dialog box appear. Use the dialog box to locate a folder where we wish to save the database file. Enter file name, visual data manager automatically saves the file with .MDB extension.
- Now we will add a table to database file. Right click in the database window. On the popup menu that appears, click new table. The table structure dialog box appears.
- Type table name is the table name text box. Now table is saved in .DBF file extension.
- Click the add field button in the table structure dialog box. The add field dialog box will appear. In the name text box, type field name and in the type list box, select a field type. Click OK button to select the field.
- The add field dialog box still display. Type another field name and field type and click OK button every time.
- After adding last field, click the close button on the add field dialog box. The table structure dialog box reappear. In this dialog box, we can edit in field structure.
- Click the build the table button to build the table and add it to database. The visual data manager window should appear all screen. Notice that on entry for the table new appear will appear.
- Now we are ready to add data to the table. Right click the table name entry in the data base window and select open from the popup menu.
- Click the add button. The Dynaset add record dialog box. Should appear on screen. Enter the record value of each field and click update button.
- Second record is now added to the table. Add the dynaset dialog box click the add button to add the next record. Continue this procedure to add all the remaining records in the table.
- After we have added all the records in the table, click the close button in the dynaset dialog box.
- Click file on the visual data manager menu bar. On the file menu, click exit button. Now we return to the visual basic form window.