Pregunta

I am very novice at asp. Here is my code:

response.write("<script>")
dim counter: counter = 0
do until rs.EOF
  for each x in rs.Fields
    counter = counter + 1
    response.write "var CC" & counter & "=" & x.value & ";"
  next
  rs.MoveNext
loop
response.write("</script>")

This currently returns both columns from my DB:

<script>var CC1=ALFKI;var CC2=13579;var CC3=ALFKI;var CC4=246;</script>

I only want the second column to return, which is the numbers (13579 & 246).

What should I change?

¿Fue útil?

Solución

Not sure I should be answering this, but to loop and only write out on the even iteration use Mod() to test the remainder.

response.write("<script>")
dim counter: counter = 0
do until rs.EOF
  for each x in rs.Fields
    counter = counter + 1
    'Use Mod() to check counter is even
    If counter Mod 2 = 0 Then response.write "var CC" & counter & "=" & x.value & ";"
  next
  rs.MoveNext
loop
response.write("</script>")

Useful links

Otros consejos

Ad an IF statement, based on your counter.

for each x in rs.Fields
    counter = counter + 1
    if(counter = 1) then
      response.write "var CC" & counter & "=" & x.value & ";"
    end if
next

Try this

response.write("<script>")
dim counter: counter = 0
do until rs.EOF
  for each x in rs.Fields
    counter = counter + 1
    if IsNumeric(x.value) then
        response.write "var CC" & counter & "=" & x.value & ";"
    end if
  next
  rs.MoveNext
loop
response.write("</script>")

The trick is to check "If IsNumeric" then do what you want.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top