Database to array

I am trying to write a VBScript UFT test that gets a dataset from a table (this will be 100 records). I'm only going to select one column, as you can see from the query below.

SELECT TOP 100 l_Name FROM lessee

I managed to display the first entry in the message box, but I did it only as a test. What I'm trying to do now is add each record to an array so that I can skip them later to change the value of the WebEdit text box.

Below is my current code, but it's hard for me to figure this out.

Dim DBQuery 
DBQuery = "Select top 100 l_Name from lessee"

objConnection.Open "Provider=sqloledb.1;Server=TestServer;User Id=User;Password=Test123;Database=DBTest"

objRecordSet.Open DBQuery,objConnection

' Return the Result Set  '''
For Each element In ObjRecordset.Fields.Item
    Value = objRecordSet.fields.item(element)               
    MsgBox Value
Next

' Release the Resources  '''
objRecordSet.Close        
objConnection.Close     

Set objConnection = Nothing
Set objRecordSet = Nothing

I assumed that looping back records would work.

0
source share
2 answers

@trincot , ADODB.Recordset, Array, .

Dim data
'... (Recordset connection and execution code omitted)
If Not objRecordset.EOF Then data = objRecordset.GetRows()

GetRows() . , , , , , data,

If IsArray(data) Then
  value = data(1, 4)
End If

. Array , 1, - 4.

For, :

Dim row, rows

If IsArray(data) Then
  rows = UBound(data, 2)
  For row = 0 To rows
    'First column of the current row
    WScript.Echo data(0, row)
    'Second column of the current row
    WScript.Echo data(1, row)
    '... etc
  Next
End If
+2

, , (), . , ( ) .

, .

:

Do While Not objRecordSet.EOF
    value = objRecordSet("l_Name")

    ' do something with value
    '
    objRecordSet.MoveNext
Loop
+2

Source: https://habr.com/ru/post/1651332/


All Articles