FireDAC.TFDMemTable.IncFetchingMSSQL Sample

From RAD Studio Code Examples
Jump to: navigation, search

This sample demonstrates how to use the Fetch and FetchAll methods in order to fetch rows from the current command cursor.

Location

You can find the IncFetchingMSSQL sample project at:

Description

The IncFetchingMSSQL sample shows you how to fetch rows from the current command cursor. To this end, the sample connects to the desired database using the MSSQL_Demo connection definition. Then, the sample uses Fetch and FetchAll methods in order to fetch the rows that match with a given selection made by the user.

How to Use the Sample

  1. Navigate to the location given above and open IncFetching.dproj.
  2. Press F9 or choose Run > Run.

Files

File in Delphi Contains

IncFetching.dproj
IncFetching.dpr

The project itself.

Unit30.pas
Unit30.fmx

The main form.

Implementation

This sample uses the following main components that are configured at design time using the Object Inspector:

It uses TFDConnection to connect to the desired database. In the CommandText property of TFDCommand there is a SQL command that, in this sample, is used for selecting the desired data from the desired database. In the sample, the CommandText property is set to: select * from Orders where EmployeeID = :ID, which means that, in this sample, the user can fetch the rows with a given value of the EmployeeID field from the Orders table. You can check it on the Object Inspector.
It provides communication between the application and the database. It is a mediator between TFDCommand and TFDMemTable. To this end, the SelectCommand property is set to FDCommand1 at design time using the Object Inspector.
It retrieves data from database through TFDTableAdapter and TFDCommand. To this end, the Adapter property is set to FDTableAdapter1 at design time using the Object Inspector.

Moreover, the goal of the sample is to fetch the desired rows from a given database table. First, the sample sets the condition that have to meet the rows in order to be selected; then, the sample uses the Open method to open the dataset and finally, calls the FetchAll method to fetch all rows that match with the desired selection. See the code below:

  FDCommand1.Params[0].AsInteger := 1;
  FDMemTable1.Open;
  FDMemTable1.FetchAll;
Note: This piece of code fetches all rows from the Orders table that have the value of the EmployeeID field set to 1.

Then, this process is repeated in order to make an incremental fetch of rows that match the desired selection for each case. See the code below:

  FDCommand1.Params[0].AsInteger := 2;
  // Fetching process
 
  FDCommand1.Params[0].AsInteger := 3;
  // Fetching process
 
  // ...

Uses

See Also

Samples

Personal tools
RAD Studio 10.2 Tokyo
Assistance