do while not rs.eof
str1 = str1 & rs("id") & ","
str2 = str2 & rs("name") & ","
rs.movenext
loop
rs.close
str1 = Left(str1, len(str1)-1)
str2 = Left(str2, len(str2)-1)
arr1 = split(str1, ",")
arr2 = split(str2, ",")
Main Topics
Browse All Topicsi have a sql query - select id, name from table1. I want to store the 2 values into 2 array (size is unknown) in classic ASP. Example please.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Dim id()
Dim name()
Dim intIndex
intIndex = 0
strGetInfo = "SELECT id, name FROM table1"
' Unique to SQL object (objConn).
objConn.ConnectionString = "Driver={SQL Server};Server=<servername
Database=<database>;Uid=<u
objConn.Open ' Initiate SQL connection.
Set objInfo = objConn.Execute(strGetInfo
Do While Not objnfo.EOF
ReDim Preserve id(intIndex)
ReDim Preserve name(intIndex)
id(intIndex) = objInfo.Fields("id")
name(intIndex) = objInfo.Fields("name")
intIndex = intIndex + 1
objLabStatsInfo.MoveNext
Loop
For n = 0 to Ubound(id)
Response.Write id(n)
Next
For o = 0 to Ubound(name)
Response.Write name(o)
Next
Here is a simplest and most effecient way (IMO):
<%
sqlstr = "select id, name from table1"
myArray = getrows(sqlstr)
for i = lbound(myArray) to ubound(myArray)
response.write myArray(1, i) & ", " & myArray(0, i) & "<BR>"
next
%>
<%
function getrows(sqlstr)
dim recobj
set recobj = connection_open(sqlstr)
getrows = recobj.getrows()
recobj.close
set recobj = nothing
end function
function connection_open(sqlstring)
dim recobj01, connobj
set connobj = Server.CreateObject("ADODB
connobj.Open "DSN=myDSN","myUser","myPa
set recobj01 = Server.CreateObject("ADODB
recobj01.CursorLocation = 3
recobj01.Open sqlstring, connobj
set connection_open = recobj01
set recobj01 = nothing
set connobj = nothing
if err <> 0 then
response.write "An error occurred: " & err.description
end if
end function
%>
I agree with calvin that Recordset.GetRows is probably the fastest and simplest method.
His sample code does however not create 2 arrays - that is what i understand what should happen.
<%
sSQL = "select id, name from table1"
aRows = connection.Execute(sSQL).G
ReDim aIdArray(Ubound(aRows)-1)
ReDim aNameArray(Ubound(aRows)-1
For i = 0 To Ubound(aRows)
aIdArray(i) = aRows(0,i)
aNameArray(i) = aRows(1,i)
Next
%>
hi sybe,
Yes, I do notice the two arrays is stated in the question.
However, since both arrays will definately have same number of rows, why not make it into one 2-column array instead? the coding is much cleaner, less memory usage, and execution is faster as well. :)
since the ID, NAME, is linked directly to each other, I don't see any reason why it should split to two arrays. :)
Business Accounts
Answer for Membership
by: leechoonhweePosted on 2004-06-17 at 20:19:24ID: 11340916
Dim strArray()
)
Sql = "Select id,Name from Table1"
Set rst=conn.execute(sql)
Redim strArray(rst.recordcount,1
WHile not rst.eof
For i = 0 to rst.recordcount
strarray(i,0) = rst("ID")
strarray(i,1) = rst!("Name")
Next
rst.movenext
Wend