1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

ASP database select loop

Discussion in 'C#' started by Cinta April, Jun 26, 2008.

  1. #1
    Hi I am trying to do a select query in a select query but the page just hanged. I am using oracle as database. Is there any problem with Oracle?
     
    Cinta April, Jun 26, 2008 IP
  2. dylanj

    dylanj Peon

    Messages:
    173
    Likes Received:
    3
    Best Answers:
    1
    Trophy Points:
    0
    #2
    The problem is most likely in your code. Could you post the loop code?
     
    dylanj, Jun 26, 2008 IP
  3. Cinta April

    Cinta April Banned

    Messages:
    262
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    sql = "bla bla bla"
    rs.Open sql, conn
    do while NOT rs.eof
    sql2 = "bla bla bla2"
    rs2.Open sql2, conn
    do while not rs2.eof
    Loop
    Loop

    Error
     
    Cinta April, Jun 26, 2008 IP
  4. wowla_123

    wowla_123 Peon

    Messages:
    147
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #4
    sql = "bla bla bla"
    rs.Open sql, conn
    do while NOT rs.eof
       sql2 = "bla bla bla2"
       rs2.Open sql2, conn
       do while not rs2.eof    'What is the need of this loop?
           rs2.MoveNext
       Loop
       rs.MoveNext
    Loop
    Code (markup):
     
    wowla_123, Jun 26, 2008 IP
  5. Cinta April

    Cinta April Banned

    Messages:
    262
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    it's the whole point loop in a loop. I can do it with PHP. Is there a way to do it with ASP?
     
    Cinta April, Jun 26, 2008 IP
  6. roym

    roym Peon

    Messages:
    38
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #6
    assume your closing the connection in the second loop after you finish with it?
     
    roym, Jun 26, 2008 IP
  7. Sleeping Troll

    Sleeping Troll Peon

    Messages:
    217
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Your do while has no code between it and loop, therefore endless loop.
     
    Sleeping Troll, Jun 26, 2008 IP
  8. Cinta April

    Cinta April Banned

    Messages:
    262
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #8
    are u sure it's endless loop bcuz the conditon is do while not rs.eof obviously when it reached the end, it stops. Does anybody has a loop like mine, post it here? Or is this kind of loop not possible in ASP? Then PHP ispossibly more powerful than ASP in terms of loop in a loop.
     
    Cinta April, Jun 26, 2008 IP
  9. dylanj

    dylanj Peon

    Messages:
    173
    Likes Received:
    3
    Best Answers:
    1
    Trophy Points:
    0
    #9
    
    sql = "bla bla bla"
    rs.Open sql, conn
    do until rs.eof
       sql2 = "bla bla bla2"
       rs2.Open sql2, conn
       do until rs2.eof
           rs2.MoveNext
       loop
       rs.MoveNext
    loop
    
    Code (markup):
    Personally, that's how I would code it. The only thing is this:
    
    do until rs2.eof
      rs2.MoveNext
    loop
    
    Code (markup):
    I don't know for sure, but this bit of code seems a little useless? I mean, all it's doing is moving to the last record in the database... You could just use rs.MoveLast.

    If you're just trying to put a loop in a loop, then i'll assure you that you can put a loop in a loop:
    
    i = 0
    e = 0
    Do Until i = 10
      i = i + 1
      Response.Write("<br />this will be written a total of 10 times<br />")
      Do Until e = 10
        e = e + 1
        Response.Write("this will be written 10 times under each i, to a total of 100 times<br />")
      Loop
      e = 0
    Loop
    
    Code (markup):
    Put that in a lone ASP file. I guarantee it will work :)
     
    dylanj, Jun 26, 2008 IP
  10. shaileshk

    shaileshk Well-Known Member

    Messages:
    455
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    108
    #10
    
    sql = "bla bla bla"
    rs.Open sql, conn
    do while NOT rs.eof
       sql2 = "bla bla bla2"
       rs2.Open sql2, conn
       do while not rs2.eof    'What is the need of this loop?
           rs2.MoveNext
       Loop
    [COLOR="Red"]rs2.close[/COLOR]
       rs.MoveNext
    Loop
    
    Code (markup):
    Please close rs1 and rs2 recordset after your loop is over.
     
    shaileshk, Jun 27, 2008 IP
  11. roym

    roym Peon

    Messages:
    38
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #11
    Just realised what's wrong in general with this (don't know why I didn't think last night), but you shouldn't need to do a loop within a loop. You just need to code the select from the database different as in an outer join and an order by (or the oracle equivalent) and then use a single loop to output it.
     
    roym, Jun 27, 2008 IP
  12. Cinta April

    Cinta April Banned

    Messages:
    262
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #12
    the question is about query loop, not response loop. how does closing the record matters? i know there are procedures in oracle, but i'm trying to put away with that and code it with ASP. So it is not possible to do a loop in a loop query with ASP?
     
    Cinta April, Jun 27, 2008 IP
  13. roym

    roym Peon

    Messages:
    38
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #13
    it is possible but generally pointless in any language/db, the reason being if you are pulling the records back from the database you just use an outer join to in effect do the second loop in the database. Because from a coding point of view it's highly highly inefficent to repeatedly query a database within a loop which is the result of a database query, as the join on the database side is considerably more efficent. As for closing the connection, in this case it's an issue because within the second loop you call Open each time you loop, this will mean that you will have as many connections open to your database as "number of loops for the first loop". So say you looped 100 times in the outer loop you would have over 100 open database connections "gulp!" (as in your IIS or apache server is connected 100 times to your db!) a sure way to kill your database when you get more than a few users at a time. Anyhow it's difficult to say more without seeing the code and db query, and admittedly I'm more an MS SQL server and .net guy than classic ASP (it's been over 8 years since I last touched that). But if you can post or pm me the code I'll have a look at it as soon as I can (maybe a day or two). But as a VERY VERY strong recommendation do your basic record processing on the database that's what it's designed for, and your user interaction/business logic in your server side code. hope that helps.
     
    roym, Jun 27, 2008 IP