+ Reply to Thread
Results 1 to 10 of 10

Thread: retreive DB values into a DD box

  1. #1
    Barn Enthusiast Centurion is on a distinguished road Centurion's Avatar
    Join Date
    Dec 2008
    Posts
    429
    Rep Power
    2

    retreive DB values into a DD box

    Code:
    	<fieldset style="padding: 2; width:600px; height:53">
    	<legend><font color="#0000FF"><b>Talent Review</b></font></legend>
    	<font face="Arial">
    	<font size="2">&nbsp; 4</font><font size="2" face="Arial">) High 
    	Potential:</font>
    
    	<select name="High_Potential" size="1" style="width: 111; height: 21" >
    				<option selected>Choose One...</option>
    				<option value="Yes0" >Yes</option>
    				<option value="No0" >No</option>
    			</select ><font color="#FF0000"><%=response.write(rs("High_Potential"))%></font>
    	</font>
    	</fieldset></p>
    
    As you can see above i have used response.write to show the user what value is in the DB.. but how do i get the value to automatically show up in the drop down list?

  2. #2
    Barn Loyal Rebelle will become famous soon enough Rebelle's Avatar
    Join Date
    Mar 2008
    Posts
    868
    Rep Power
    3

    Hi wbva,

    you need a select query....also, it appears your response.write is on the outside of the </select> tag. ?

    How about something like this...

    Code:
    <select name="High_Potential" size="1" style="width: 111; height: 21" >
    <%
    Set Rs=Server.CreateObject("adodb.recordset")
    strSQL = "SELECT DISTINCT HighPotential FROM yourTableName"
    strSQL = strSQL & " ORDER BY HighPotential"
    Rs.Open strSQL, conn
    
    Do while not Rs.EOF
       if Request.Form("High_Potential") = Rs("High_Potential") then
          Response.Write "<OPTION VALUE = '" & Rs("High_Potential") & "' SELECTED>"
          Response.Write Rs("High_Potential") & "</Option>"
          Rs.MoveNext
       else
          Response.Write "<OPTION VALUE = '" & Rs("High_Potential") & "'>"
          Response.Write Rs("High_Potential") & "</Option>"
          Rs.MoveNext
       end if
    loop
    
    %>
    </SELECT>
    

  3. #3
    Barn Enthusiast Centurion is on a distinguished road Centurion's Avatar
    Join Date
    Dec 2008
    Posts
    429
    Rep Power
    2

    Quote Originally Posted by Rebelle View Post
    Hi wbva,

    you need a select query....also, it appears your response.write is on the outside of the </select> tag. ?

    How about something like this...

    Code:
    <select name="High_Potential" size="1" style="width: 111; height: 21" >
    <%
    Set Rs=Server.CreateObject("adodb.recordset")
    strSQL = "SELECT DISTINCT HighPotential FROM yourTableName"
    strSQL = strSQL & " ORDER BY HighPotential"
    Rs.Open strSQL, conn
    
    Do while not Rs.EOF
       if Request.Form("High_Potential") = Rs("High_Potential") then
          Response.Write "<OPTION VALUE = '" & Rs("High_Potential") & "' SELECTED>"
          Response.Write Rs("High_Potential") & "</Option>"
          Rs.MoveNext
       else
          Response.Write "<OPTION VALUE = '" & Rs("High_Potential") & "'>"
          Response.Write Rs("High_Potential") & "</Option>"
          Rs.MoveNext
       end if
    loop
    
    %>
    </SELECT>
    
    hi, thanks for that.. but i have another query running at the top of the page... so i assume i change Rs to rs1 and it did seem to work.. but basically the page is so the user can update. and it only has Choose One in the box.. as its querying on those values. how would i add other selectable values ?

    Code:
    <%
    'Checking to see what request is being submitted
    	IF  Request.Form("submit")="submit" Then
    	
    	username=request.form("username")    ' Get the unique Ref being searched for
    	
    	'create a record set
    		Set rs=Server.CreateObject("ADODB.RecordSet")
    	'Query the database
    		sql= "SELECT * FROM [Exec-3] WHERE username = '" & username& "'"
    		rs.open sql, conn, 1, 1
    		IF NOT rs.eof THEN
    		
    		response.write sql
    		
    
    		
    
    %>
    

  4. #4
    Barn Loyal Rebelle will become famous soon enough Rebelle's Avatar
    Join Date
    Mar 2008
    Posts
    868
    Rep Power
    3

    Hi wbva,

    Not sure what you mean "other selectable values"...? .. other value other than from database?

    Also, if you already had query at the top of page then you don't have to repeat...just start with the do while line.

  5. #5
    Barn Enthusiast Centurion is on a distinguished road Centurion's Avatar
    Join Date
    Dec 2008
    Posts
    429
    Rep Power
    2

    Quote Originally Posted by Rebelle View Post
    Hi wbva,

    Not sure what you mean "other selectable values"...? .. other value other than from database?

    Also, if you already had query at the top of page then you don't have to repeat...just start with the do while line.
    I want to retreive the selected value from the database.. but also i want the option of having static values from the drop down list..

    say the drop down retreives 'Yes' but the user wants to change this to 'No'.. they cant seem to do that as all the code does is retreieve.

  6. #6
    Barn Loyal Rebelle will become famous soon enough Rebelle's Avatar
    Join Date
    Mar 2008
    Posts
    868
    Rep Power
    3

    ok, thought that but wanted to clarify .. .how about line in blue...i may have quotes wrong but give it a try.

    Do while not Rs.EOF
    if Request.Form("High_Potential") = Rs("High_Potential") then
    Response.Write "<OPTION VALUE = 'No' SELECTED>"No</Option>"
    Response.Write "<OPTION VALUE = '" & Rs("High_Potential") & "' SELECTED>"
    Response.Write Rs("High_Potential") & "</Option>"
    Rs.MoveNext
    else
    Response.Write "<OPTION VALUE = 'No' SELECTED>"No</Option>"
    Response.Write "<OPTION VALUE = '" & Rs("High_Potential") & "'>"
    Response.Write Rs("High_Potential") & "</Option>"
    Rs.MoveNext
    end if
    loop

  7. #7
    Barn Frequenter BLaaaaaaaaaarche will become famous soon enough BLaaaaaaaaaarche will become famous soon enough BLaaaaaaaaaarche's Avatar
    Join Date
    Mar 2008
    Posts
    165
    Rep Power
    4

    Rebelle, you can achieve the same thing with much less code, using this logic:

    Code:
    Do While Not rs.EOF
    	strHP = rs("High_Potential")
    	response.write "<option value=""" & strHP & """"
    	If CStr(Request.Form("High_Potential")) = CStr(strHP) Then
    		response.write " selected"
    	End If
    	response.write ">" & strHP & "</option>" & vbCrLf
    rs.MoveNext
    Loop
    
    Just thought I would share that with you.

    WBVA, I have no clue what you are trying to say. Can you please rephrase your question?
    "You'll never be as perfect as BLaaaaaaaaarche."

  8. #8
    Barn Enthusiast Centurion is on a distinguished road Centurion's Avatar
    Join Date
    Dec 2008
    Posts
    429
    Rep Power
    2

    Quote Originally Posted by BLaaaaaaaaaarche View Post
    Rebelle, you can achieve the same thing with much less code, using this logic:

    Code:
    Do While Not rs.EOF
    	strHP = rs("High_Potential")
    	response.write "<option value=""" & strHP & """"
    	If CStr(Request.Form("High_Potential")) = CStr(strHP) Then
    		response.write " selected"
    	End If
    	response.write ">" & strHP & "</option>" & vbCrLf
    rs.MoveNext
    Loop
    
    Just thought I would share that with you.

    WBVA, I have no clue what you are trying to say. Can you please rephrase your question?
    Thanks for the code.. basically what i want to do is:

    have a drop down box with the values Yes, No and N/A.

    If the user (from another page) has inserted Yes, then my update page should retreive Yes into the drop down box.

    As this is an update page it should have a choice of the other values in case the user wants to change the value to No.

  9. #9
    Barn Enthusiast Centurion is on a distinguished road Centurion's Avatar
    Join Date
    Dec 2008
    Posts
    429
    Rep Power
    2

    got this error :

    Error Type:
    ADODB.Field (0x80020009)
    Either BOF or EOF is True, or the current record has been deleted. Requested operation requires a current record.
    admin/Form3_Update.asp, line 93

  10. #10
    The Barnfather jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead's Avatar
    Join Date
    Mar 2008
    Location
    Washington, D.C.
    Posts
    2,347
    Blog Entries
    9
    Rep Power
    19

    Put BLarche's code between this:
    Code:
    If Not rs.BOF And Not rs.EOF Then
        ' BLarche's code here
    End If
    
    jmurrayhead
    If you agree, give me rep. If my post helped you, click "Thanks".
    If you like it here...throw us a few bones to help support us.


+ Reply to Thread

Similar Threads

  1. best way to bind values to sql statement?
    By Centurion in forum ASP Development
    Replies: 11
    Last Post: March 17th, 2009, 06:45 AM
  2. getting values from tables
    By todd2006 in forum ASP Development
    Replies: 7
    Last Post: February 2nd, 2009, 06:33 PM
  3. Converting Null Values to Zero
    By nboscaino in forum Microsoft Access
    Replies: 3
    Last Post: September 4th, 2008, 01:02 PM
  4. finding values
    By todd2006 in forum ASP Development
    Replies: 2
    Last Post: June 23rd, 2008, 02:03 AM
  5. retrieve values
    By todd2006 in forum SQL Development
    Replies: 5
    Last Post: June 19th, 2008, 01:46 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

SEO by vBSEO