inserting option values into drop down lists with getstring when using distinct in the SQL

Ask a Question related to ASP Database, Design and Development.

  1. #1

    Default Re: inserting option values into drop down lists with getstring when using distinct in the SQL

    I don't know what your problem is. It works fine for me. Here is my code:

    <%
    dim cn,rs
    set cn=server.CreateObject("adodb.connection")

    sSQL="SELECT job_desc FROM dbo.jobs"
    cn.open "provider=sqloledb;data source=censored;" & _
    "user id = censored; password=censored;initial catalog=pubs"
    set rs=cn.execute(sSQL,,adCmdText)
    Response.Write "<select name=""artist"">" & _
    "<option selected>Choose</option>"
    Response.Write("<option value='")
    Response.Write RS.GetString( ,,,"</option><option>")
    Response.Write("</option></select>")
    RS.close
    set RS = Nothing
    cn.close
    Set cn = Nothing
    %>

    HTH,
    Bob Barrows

    julian wrote:
    > hi
    >
    > i have a problem here that i think may be obvious but i cant see it.
    > Please can someone help?
    >
    > With .ASP i am pulling records from an Access database and placing
    > them into a drop down list. I am using getstring() but cannot get the
    > option values (line 15) for the drop down list to insert.
    >
    > It works if my SQL (line 3) is
    > Set RS = db.Execute("SELECT DISTINCT Filed3, Field3 FROM IaxData")
    > But this doesnt look efficient or right?
    >
    >
    >
    > 1. Set db = Server.CreateObject("ADODB.Connection")
    > 2. db.Open "dsn=database2;"
    > 3. Set RS = db.Execute("SELECT DISTINCT Field3 FROM IaxData")
    > 4.
    > 5. If RS.eof then
    > 6. Response.Write "Sorry, No records were found.<br>"
    > 7. set objRS = Nothing
    > 8. db.close
    > 9. Set db = Nothing
    > 10 Response.End
    > 11 End If
    > 12
    > 13 Response.Write "<select name=""artist""><option
    > selected>Choose</option>"
    > 14 Response.Write("<option value='")
    > 15 Response.Write RS.GetString(,,,"</option><option>")
    > 16 Response.Write("</option></select>")
    > 17
    > 18 RS.close
    > 19 set RS = Nothing
    > 20 db.close
    > 21 Set db = Nothing
    >
    >
    > thx anyone in advance


    Bob Barrows Guest

  2. Similar Questions and Discussions

    1. coldfusion drop down lists
      i am trying to build a page with two drop down lists. one with user ids, pulling the list of ids from form variables. the other lists is projects,...
    2. Change option in second drop down box based on selectionof first drop down box
      Change option in second drop down box based on selection of first drop down box. Hi, I am trying to figure out how to make a selection in 1...
    3. Datagrid with Drop Down Lists
      In an asp.net page that has a datagrid, how do you change the data for that column to be listed in a listbox with the current value selected?
    4. Form data - drop down values/display option
      I have a drop down box where the choices are populated from a database query, this part works fine: <option value><% = strEmail %></option> I...
    5. 2 drop-down lists
      Micha wrote: PHP runs on the server. You need client-side scripting, probably Javascript. Cross-posted and followups set. -- Jim Dabell
  3. #2

    Default Re: inserting option values into drop down lists with getstring when using distinct in the SQL

    Response.Write("<option value='")
    Response.Write RS.GetString( ,,,"</option><option>")
    Response.Write("</option></select>")

    Perhaps this is not the best method, since you need to get the value twice
    for each row, once for the value parameter and once for the text.

    Your code would return (line breaks added for clarity)

    <option value='val1</option>
    <option>val2</option>
    etc...
    </option>
    </select>

    First item has no closing single quote and none of the other items have a
    value attribute.


    Tim.



    "julian" <julian.cheung@talk21.com> wrote in message
    news:1994ccb7.0307241120.2d345e3d@posting.google.c om...
    > hi
    >
    > i have a problem here that i think may be obvious but i cant see it.
    > Please can someone help?
    >
    > With .ASP i am pulling records from an Access database and placing
    > them into a drop down list. I am using getstring() but cannot get the
    > option values (line 15) for the drop down list to insert.
    >
    > It works if my SQL (line 3) is
    > Set RS = db.Execute("SELECT DISTINCT Filed3, Field3 FROM IaxData")
    > But this doesnt look efficient or right?
    >
    >
    >
    > 1. Set db = Server.CreateObject("ADODB.Connection")
    > 2. db.Open "dsn=database2;"
    > 3. Set RS = db.Execute("SELECT DISTINCT Field3 FROM IaxData")
    > 4.
    > 5. If RS.eof then
    > 6. Response.Write "Sorry, No records were found.<br>"
    > 7. set objRS = Nothing
    > 8. db.close
    > 9. Set db = Nothing
    > 10 Response.End
    > 11 End If
    > 12
    > 13 Response.Write "<select name=""artist""><option
    > selected>Choose</option>"
    > 14 Response.Write("<option value='")
    > 15 Response.Write RS.GetString(,,,"</option><option>")
    > 16 Response.Write("</option></select>")
    > 17
    > 18 RS.close
    > 19 set RS = Nothing
    > 20 db.close
    > 21 Set db = Nothing
    >
    >
    > thx anyone in advance

    Tim Williams Guest

  4. #3

    Default Re: inserting option values into drop down lists with getstring when using distinct in the SQL

    Very true.
    A better technique would be (assuming SQL Server):
    SQL = "Select distinct '<option value=""' + field3 + '"">'" & _
    " + field3 +'</option>' from IaxData"
    Set RS = db.Execute(SQL,,1)
    'check for EOF then
    Response.Write "<select name=""artist""><option" & _
    "selected>Choose</option>" & vbcrlf
    Response.Write RS.GetString(,,,vbcrlf)
    Response.Write("</select>")

    HTH,
    Bob Barrows


    Tim Williams wrote:
    > Response.Write("<option value='")
    > Response.Write RS.GetString( ,,,"</option><option>")
    > Response.Write("</option></select>")
    >
    > Perhaps this is not the best method, since you need to get the value
    > twice for each row, once for the value parameter and once for the
    > text.
    >
    > Your code would return (line breaks added for clarity)
    >
    > <option value='val1</option>
    > <option>val2</option>
    > etc...
    > </option>
    > </select>
    >
    > First item has no closing single quote and none of the other items
    > have a value attribute.
    >
    >
    > Tim.
    >
    >
    >
    > "julian" <julian.cheung@talk21.com> wrote in message
    > news:1994ccb7.0307241120.2d345e3d@posting.google.c om...
    >> hi
    >>
    >> i have a problem here that i think may be obvious but i cant see it.
    >> Please can someone help?
    >>
    >> With .ASP i am pulling records from an Access database and placing
    >> them into a drop down list. I am using getstring() but cannot get the
    >> option values (line 15) for the drop down list to insert.
    >>
    >> It works if my SQL (line 3) is
    >> Set RS = db.Execute("SELECT DISTINCT Filed3, Field3 FROM IaxData")
    >> But this doesnt look efficient or right?
    >>
    >>
    >>
    >> 1. Set db = Server.CreateObject("ADODB.Connection")
    >> 2. db.Open "dsn=database2;"
    >> 3. Set RS = db.Execute("SELECT DISTINCT Field3 FROM IaxData")
    >> 4.
    >> 5. If RS.eof then
    >> 6. Response.Write "Sorry, No records were found.<br>"
    >> 7. set objRS = Nothing
    >> 8. db.close
    >> 9. Set db = Nothing
    >> 10 Response.End
    >> 11 End If
    >> 12
    >> 13 Response.Write "<select name=""artist""><option
    >> selected>Choose</option>"
    >> 14 Response.Write("<option value='")
    >> 15 Response.Write RS.GetString(,,,"</option><option>")
    >> 16 Response.Write("</option></select>")
    >> 17
    >> 18 RS.close
    >> 19 set RS = Nothing
    >> 20 db.close
    >> 21 Set db = Nothing
    >>
    >>
    >> thx anyone in advance


    Bob Barrows Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139