How To Pass a Variant Array Populated with a RecordSet From a VB Component to an ASP Page, Part 2By Doug Dean
In Part 1 we looked at a VB component that grabbed information from
a database table, stuffing it into an array using the
GetRows method of the Recordset object.
In this part we'll look at the ASP page and how, exactly, it will retrieve this variant array and access its
THE ASP FILE - How2Project3.asp
The Variable Array Structure
We'll be receiving a Variant array in our asp file that will be populated with the RecordSet field values from our method call. We'll assign the field values to a variable we'll name
But before we cover the asp code, some explanation of the array structure is in order. The
vRecordArray values were originally obtained via the ADO
GetRows Method in
our VB code - thus the vRecordArray array structure will be a two-dimensional array. The array is zero
based. The first subscript will identify the fields of the database and the second the record number.
FIELD_INDEX will index the fields returned. Since we'll be identifying three fields
in our sql statement (
this first subscript will be indexed from 0 to 2. With 0 being the index for the first field named
ExampleFieldID, 1 the index for
ExampleField1, and 2 the index for
The returned two-dimensional array mimics the database rows and columns as identified in our SQL
statement. So if we wanted the fifth record value of the
ExampleField2 field, our first
subscript would be 2 and our second would be 4.
LngVariable would contain "Text Field 2e"
The two following tables show the database and array results of the following SQL statement:
|Database rows and columns determined by the SQL statement|
|1||100||"Text Field 2a"|
|2||200||"Text Field 2b"|
|3||300||"Text Field 2c"|
|4||400||"Text Field 2d"|
|5||500||"Text Field 2e"|
|6||600||"Text Field 2f"|
|Array index structure of |
The Asp Code
Rather than using numerical values for our first subscript (
FIELD_INDEX), we'll assign
constants named after our database fields. This way we may avoid maintenance and debugging difficulties.
vRecordArray(2,4) can be stated as
We'll first need to instantiate the VB object within the asp file with the following statement and then assign values to the two parameters used in the method.
Assigning the Variant array is easy.
We end by setting out object to
We now have a Variant array filled with the record values we indicated in our SQL statement. For this example we'll use them to fill a HTML TABLE. To see how we'll accomplish this, read Part 3!