jasonsalas
IS-IT--Management
What's the best qay to populate the elements of an Array object in VBScript for ASP 3.0 coming out of a database? I'm stuck on this one.
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
dim myArray(10,2) 'maximum 11 rows with 3 fields
dim ctr
ctr = 0
Do Until rs.EOF
myArray(ctr,0) = rs("firstField")
myArray(ctr,1) = rs("secondField")
myArray(ctr,2) = rs("thirdField")
ctr = ctr + 1
rs.MoveNext
Loop
Dim myArray(1000,15) 'max 1001 records w/ 16 fields each
Dim rowCtr, fieldCtr, numFields
numFields = rs.fields.count
For fieldCtr = 0 to numFields - 1
myArray(0,fieldCtr) = rs.fields.item(fieldCtr).name 'check syntax on this one
Next
rowCtr = 1
Do Until rs.EOF
For fieldCtr = 0 to numFields - 1
myArray(rowCtr,fieldCtr) = rs.fields.item(fieldCtr)
Next
rs.MoveNext
rowCtr = rowCtr + 1
Loop
'This sample code demonstrates how to pass an array of field
'names to the GetRows Fields Option.
Dim cn As New Connection
Dim rs As New Recordset
Dim vFields() As Variant
Dim vdata as Variant
'This example is connecting to SQL Server's Sample Pubs database.
cn.Open "driver={SQL Server};" & _
"server=<server_name>;uid=<user_id>;pwd=<password>;database=pubs"
rs.Open "select * from authors", cn
ReDim vFields(1)
vFields(0) = "au_fname"
vFields(1) = "au_lname"
vData = rs.GetRows(adGetRowsRest, , vFields)
For i = 0 To UBound(vdata, 2) - 1
Debug.Print vdata(0, i) & " " & vdata(1, i)
Next i