Connecting Your Program to The Database

Introduction

Before trying to connect your program to a database, you must create the database and an alias to it. Next you can add a table component for each of your tables and a data source component to your main form. Until you have confidence in your knowledge of databases you may also want to add a DBGrid to the form.

The Table

For most of what you will do, the TTable will do most of your work. You will only need the TDataSource and TDBGrid if you want to show your table using the TDBGrid. The values you need to set in for the table in its Object Inspector (red rectangles) are:
  • Database Name - set to the alias you created for your database
  • TableName - set to the table you want the TTable to retrieve
  • Name - actual name of the variable that will hold the TTable
  • Active - set to true after all other items are set

The Data Source

The data source severs as a connection between the Table and a DBGrid. The only thing that has to be set here is the DataSet - in this case the table you created.

The Grid

You can use the DBGrid to create a quick view of the table you are using. This is a good check to see if all the table's variables are set correctly. If the table is active, it will appear in the grid even if you are not running the program (see below). While the DBGrid is good for small tables, you will probably not be able to display large tables. All you need to do to activate the grid is assign the datasource to the source you just created.