ASP - Calling a result set and populate as selection from DB

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • yimma216
    New Member
    • Jul 2008
    • 44

    ASP - Calling a result set and populate as selection from DB

    Hi, I am trying to call a recordset from sql server and populate them into a html drop sown selection box.

    Code:
     Set conn = CreateObject("ADODB.Connection") 
    conn.Open "Driver={SQL Server};Server=cslproxy;Database=gra;Trusted_Connection=yes;"
    sql = "select * from rerturn_reasons"
    rs2.open sql, conn
    If Not rs2.eof Then
    	response.write vbcrlf & "<tr><td>Reason for Return:</td><td><select name=selectreason>"
     
    Do While Not rs2.eof
    	response.write vbcrlf & "<option"
    If rs2(0) = rs2("option_text") Then
    	response.write vbcrlf & "selected=selected"
    	End If
    response.write ">" & rs2("option_text") & "</option>"
    	rs2.movenext
    Loop
    response.write vbcrlf & "</select></td></tr>"
    End if
    rs2.close
    conn.close

    but i got error on it. Could any body check my code?
    Last edited by DrBunchman; Jul 17 '08, 07:06 AM. Reason: Added [Code] Tags - Please use the '#' button
  • idsanjeev
    New Member
    • Oct 2007
    • 241

    #2
    can you provide more detials about error

    Comment

    • DrBunchman
      Recognized Expert Contributor
      • Jan 2008
      • 979

      #3
      As idsanjeev says we'll need the error to be sure of what the problem is. Glancing at your code though you don't seem to create your recordset object anywhere e.g.
      Code:
      Set rs2 = CreateObject("ADODB.RecordSet")
      Dr B

      Comment

      • jeffstl
        Recognized Expert Contributor
        • Feb 2008
        • 432

        #4
        Without knowing which line you are getting the error, I am seeing 2 problems that would cause errors for certain.

        One you need to specifiy the server object to create a connection. Like this

        Code:
        Set conn = Server.CreateObject("ADODB.Connection")
        Second thing is in ASP code, Do While loops are ended with the syntax wend (short for While Loop End I would imagine) So you need this

        Code:
        Do While
        
        Wend

        Comment

        • jhardman
          Recognized Expert Specialist
          • Jan 2007
          • 3405

          #5
          Originally posted by jeffstl
          ... in ASP code, Do While loops are ended with the syntax wend (short for While Loop End I would imagine) So you need this

          Code:
          Do While
          
          Wend
          no, "do while ... loop" is correct. There is an alternate syntax "while...we nd" which does not use the "do". these two structures are completely redundant, both work perfectly.

          Jared

          Comment

          • jeffstl
            Recognized Expert Contributor
            • Feb 2008
            • 432

            #6
            Originally posted by jhardman
            no, "do while ... loop" is correct. There is an alternate syntax "while...we nd" which does not use the "do". these two structures are completely redundant, both work perfectly.

            Jared
            woops

            Scattered brain, correct...sorry

            Comment

            • yimma216
              New Member
              • Jul 2008
              • 44

              #7
              Thanks every one, I got it fixed.

              Comment

              Working...