IDtProvider.FetchRows

Syntax

FetchRows(Count: Integer; Var Values: Array): Integer;

Parameters

Count. The number of entries, data of which should be read.

Values. Two-dimensional array, in which read values are placed.

Description

The FetchRows method reads data of the specified number of entries from the data provider and returns the number of actually read entries.

Comments

Data is read into the array passed by the link in the Values parameter.

If the volume of loaded data is known (the number of records and number of columns, in which each record data is located are known), the array, which size is larger or equal to the volume of the data, can be specified as value of the Values parameter.

If the volume of loaded data is unknown, specify the variable corresponding to the empty dynamic array as value of the Values parameter. On executing the FetchRows method the array is automatically initialized according to the calculated volume of loaded data.

NOTE. On numerous reading of data for repeated use of the same variable-array before calling the FetchRows method, the variable must be reset to zero, or a new array of required size must be initialized.

After reading the cursor in the provider moves to the next entry.

Example

Executing the example requires the Data.xls file in the disk C root directory.

Sub LoadData;
Var
    ExcelProvider: IDtExcelProvider;
    v: Array;
    Sub ShowArray(Data: Array);
    Var
        i, j: Integer;
    Begin
        For i := Data.GetLowerBound(1To Data.GetUpperBound(1Do
            For j := Data.GetLowerBound(2To Data.GetUpperBound(2Do
                Debug.Write(Data[i, j] + " ");
            End For;
            Debug.WriteLine("");
        End For;
    End Sub ShowArray;
Begin
    ExcelProvider := New DtExcelProvider.Create;
    ExcelProvider.File := "c:\Data.xls";
    ExcelProvider.DriverVersion := "Excel 5.0";
    ExcelProvider.Query := "Select * From  [Sheet1$]";
    ExcelProvider.HasHeader := False;
    ExcelProvider.FieldsFromFile;
    ExcelProvider.Open;
    //Reading of data
    Debug.WriteLine("First data array:");
    ExcelProvider.FetchRows(5, v);
    ShowArray(v);
    v := Null;
    Debug.WriteLine("Second data array:");
    ExcelProvider.FetchRows(10, v);
    ShowArray(v);
    ExcelProvider.Close;
End Sub LoadData;

On executing the example a new data provider, that imports data from Excel file, is created. Data is read from the file in two iterations, the first string is not considered as a string with names of fields. Obtained values are displayed in the development environment console.

See also:

IDtProvider