Database into an array

M

MasterChief

I have a database of Company titles that I want to grab from an access
database, put into an asp array and then pass it to javascript so I can
output it into a CSS styled javascript menu. Right now I am stuck on
how to exactly put the database entries into an asp array. Below is
what I have so far. So I want it to return distinct entries from the
Title field and put it into the array called Titles after the asp code
has done an HTMLEncode to make sure I can also pass it along to another
asp page. Basically I need to know what to put after the Do While NOT
Rs.EOF. Any help would be appreciated.
<%
Set Conn = Server.CreateObject("ADODB.Connection")
Set Rs = Server.CreateObject("ADODB.RecordSet")
Conn.Open "PhoneList"
sSQL = "SELECT DISTINCT Title FROM Everyone WHERE Location='Admin' AND
Not Title IS NULL ORDER BY Title ASC"
Set Rs = Conn.Execute(sSQL)
Do While NOT Rs.EOF

Rs.MoveNext
Loop
Rs.Close
Set Rs = Nothing
Conn.Close
Set Conn = Nothing
%>
 
C

Chris

MasterChief said:
I have a database of Company titles that I want to grab from an access
database, put into an asp array and then pass it to javascript so I can
output it into a CSS styled javascript menu. Right now I am stuck on
how to exactly put the database entries into an asp array. Below is
what I have so far. So I want it to return distinct entries from the
Title field and put it into the array called Titles after the asp code
has done an HTMLEncode to make sure I can also pass it along to another
asp page. Basically I need to know what to put after the Do While NOT
Rs.EOF. Any help would be appreciated.
<%
Set Conn = Server.CreateObject("ADODB.Connection")
Set Rs = Server.CreateObject("ADODB.RecordSet")
Conn.Open "PhoneList"
sSQL = "SELECT DISTINCT Title FROM Everyone WHERE Location='Admin' AND
Not Title IS NULL ORDER BY Title ASC"
Set Rs = Conn.Execute(sSQL)
Do While NOT Rs.EOF

Rs.MoveNext
Loop
Rs.Close
Set Rs = Nothing
Conn.Close
Set Conn = Nothing
%>
Instead of setting your record set into a local variable, just set it in
a session variable. Then all your pages can access the same record set.
 
B

Bob Barrows [MVP]

MasterChief said:
I have a database of Company titles that I want to grab from an access
database, put into an asp array and then pass it to javascript

You mean client-side code?
so I
can output it into a CSS styled javascript menu. Right now I am stuck
on how to exactly put the database entries into an asp array.
GetRows

Below is
what I have so far. So I want it to return distinct entries from the
Title field and put it into the array called Titles after the asp code
has done an HTMLEncode to make sure I can also pass it along to
another asp page. Basically I need to know what to put after the Do
While NOT Rs.EOF. Any help would be appreciated.
<% dim arData
Set Conn = Server.CreateObject("ADODB.Connection")
Set Rs = Server.CreateObject("ADODB.RecordSet")
Conn.Open "PhoneList"
sSQL = "SELECT DISTINCT Title FROM Everyone WHERE Location='Admin'
AND Not Title IS NULL ORDER BY Title ASC"
Set Rs = Conn.Execute(sSQL)
If NOT Rs.EOF then

arData=Rs.GetRows
end if

Then store the array in Session.
You will not be able to pass the array as-is to client-side script. You will
need to extract the data you want from the array, creating a delimited
string which can be passed to the client-side code which can use the Join
method to create an array from te string. I've posted examples of this in
this group in the past, so use Google to find them.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top