Delphi and Access Walkthrough
Using an SQL Query to replace our simple table control
At the moment we can read and write to our database, but we can only see a single table. Here's a snapshot of the way that data is handled in our application so far.
That FireDAC table is the limiting factor. It has an important job, working out what information to collect from the Access Database and placing the information into the DataSource so that our programs can use it. Because it's a simple Table it can only see the contents of one table at once.
We're going to replace it with a more powerful control, the Query, which can do almost anything. What it does will depend on the instructions we give it and those instructions are written in a special command language called SQL.
There are lots of online guides to SQL Here's a link to a good beginners course from W3 schools
We're going to start with the simplest possible SQL statement that will collect all records from all fields in one table. Doing that will duplicate the data that we currently get from the Table control.
The SQL command is:
We're going to replace it with a more powerful control, the Query, which can do almost anything. What it does will depend on the instructions we give it and those instructions are written in a special command language called SQL.
There are lots of online guides to SQL Here's a link to a good beginners course from W3 schools
We're going to start with the simplest possible SQL statement that will collect all records from all fields in one table. Doing that will duplicate the data that we currently get from the Table control.
The SQL command is:
SELECT * FROM PUPILS
Notice that SQL commands are usually all in Capitals. It doesn't matter whether you use capitals or not, but using them is convention and expected.
Adding the query control
Bypass the Table control
To use the results of our query, we just set the properties of TDataSource1 so that it gets its data from the query object rather than the table object.
Now run the result. You should see exactly the same data as before. That's because our SQL statement is very basic. We'll change that in the next step.