简体   繁体   中英

How to get recordset into bidimensional array in vbscript?

I want to get a table into a bidimensional array in vbscript (I'm using asp to access a mdb), anyway, I was trying to make it like this:

        'Levels'
        Dim one : one = Array()
        Dim two : two = Array()
        Dim three : three = Array()
        Dim four : four = Array()
        Dim five : five = Array()
        Dim level

        recordset.open sql, connection

        If recordset.RecordCount <> 0 Then
            For Each record In recordset
                level = record("Level")
                Select Case level
                    Case 1
                    Case 2
                    Case 3
                    Case 4
                    Case 5
                End Select
            Next
        End If

but it seems it doesn't work, also I'm not sure if the bidimensional variable declaration is the right way of doing it.

Can some one enlighten me? Thanks in advance.

Why not use the built-in GetRows() method instead. This takes your recordset and puts it into a two dimensional array. Here's the sample code from w3schools.com which illustrates this method well:

<%
set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open(Server.Mappath("northwind.mdb"))
set rs = Server.CreateObject("ADODB.recordset")
rs.Open "Select * from Customers", conn

'The first number indicates how many records to copy
'The second number indicates what recordnumber to start on
p=rs.GetRows(2,0)
rs.close
conn.close

'This example returns the value of the first
'column in the first two records
response.write(p(0,0))
response.write("<br>")
response.write(p(0,1))

'This example returns the value of the first
'three columns in the first record
response.write(p(0,0))
response.write("<br>")
response.write(p(1,0))
response.write("<br>")
response.write(p(2,0))
%>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM