Xbasic

A5_ADO_TO_ARRAY Function

Syntax

Info as P = a5_ADO_to_Array(P ado ,P do )

Arguments

Info

Pointer

Component
Description
.CurrentPage

The number of the page containing the current record.

.RecordsPerPage

The number of records per page as specified by DO.Rows.

.TotalPages

The number of pages required to return all records.

.TotalRecords

The number of records returned.

ado

Pointer

Component
Description
.Type

Default = "Access". Valid values are: "Access" = Microsoft Access .MDB database "ConnectionString" = all other database types

.LockType

Default = 3.

.CursorType

Default = 1.

.MdbFileName

The filename of the Access database. Required if ADO. Type = "Access"

.ConnectionString

The connection string. Required if ADO. Type = "connectionString"

.SQL

SQL SELECT statement.

do

Pointer

Component
Description
.Rows

Default = 10. The number of rows per page. Set to 0 to return all rows.

.Page

Default = 1. The number of pages to return.

.MaxRows

Default = 1000. The maximum number of rows to return if ADO.Rows is set to 0.

Description

Takes an Access .mdb file, or an ADO Connection string and loads the data into an array. (For help on parameters, call with "ado.Help" set to "Yes".)

Discussion

The A5_ADO_TO_ARRAY() function retrieves records from an ADO compliant database and populates an array.

Example

This example selects all records from the Customers table of the Microsoft Access Northwind Traders sample database.

dim ado as P
dim do as P
dim global ret as P
ado.mdbfilename = "c:\databases\nwind\nwind_2002.mdb"
ado.sql = "SELECT * FROM Customers;"
ret = a5_ado_to_array(ado, do)

If we look at the ret dot variable, we see four major sections.

? ret
= +array.
+error.
+fields.
+info.

The ret.info section provides information about what we retrieved.

? ret.info
= CurrentPage = 1.000000
RecordsPerPage = 10.000000
TotalPages = 9.000000
TotalRecords = 91.000000

The ret.error section contains an indication of whether there is an error and an error message.

? ret.error
= ErrorText = ""
HasError = .F.

The ret.fields section contains information about the fields of the table.

? ret.fields.fieldarray
= +1.
+2.
+3.
+4.
+5.
+6.
+7.
+8.
+9.
+10.
+11.
? ret.fields.fieldarray1.name
= "CustomerID"

The ret.array section contains the record data that was passed returned from the database.

? ret.array.row
= +1.
+2.
+3.
+4.
+5.
+6.
+7.
+8.
+9.
+10.
? ret.array.row1.data2.initial
= "Alfreds Futterkiste"

To read all the data in the array, you would have code structured as follows.

ret = a5_ado_to_array(ado,do)
for i = 1 to do.rows
    for j = 1 to ret.fields.fieldarray.size()
        data = ret.array.rowi.dataj.initial
    next j
next i

See Also