changes variables with a loop

T

technoplonker

I have a table with one Field that has 5 Values at the moment. The
number of values will change.

Is it possible to allocate the first value in the Field to a Variable
and with each iteration of the loop change the variable to = the next
value in the Field and repeat this for all Values in the Field.

Thanks in advance

TP
 
M

Mark Schupp

Are you saying that one column in the database has multiple data elements in
it? If so how are the delimited?

Show and example of your data and what you want the variable to equal for
each iteration.
 
T

TomB

A little more info would help.
If your database table is called aTable with a column called aColumn and
the data in it was

aValue1
aValue2
aValue3
aValue4
aValue5

then your code would be like......

<%

Dim cn
Dim rs
Dim sConnectionString


Dim theVariable
sConnectionString="a Valid connection String, obtained from
www.connectionstrings.com "
Set CN=CreateObject("ADODB.COnnection")
CN.Open sCOnnectionString

Set RS=CN.Execute("SELECT aColumn FROM aTable")
Do While not RS.EOF
theVariable=RS.Fields("aColumn")
Response.write "<li>" & theVariable & "</li>" & vbCrLf
RS.MoveNext
Loop
Set RS=nothing
CN.Close
Set CN=nothing
%>


would produce

<li>aValue1</li>
<li>aValue2</li>
<li>aValue3</li>
<li>aValue4</li>
<li>aValue5</li>
 

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
474,142
Messages
2,570,820
Members
47,367
Latest member
mahdiharooniir

Latest Threads

Top