Results 1 to 2 of 2

Thread: asp/ado

  1. #1
    Join Date
    Oct 2003
    Posts
    7

    Unanswered: asp/ado

    hi i'm trying to create a drop down menu which calls the items listed from a database. for some reason i get a 'can't display window or can't find window' what am i doinf wrong. pls pls help!!!





    <html>
    <body>
    <link href="ConnectDB.asp">
    <%
    dim connectionString
    dim noRecsCode
    dim connectDB

    connectionString = "Driver={SQL Server}";
    connectionString = connectionString & "Server=MISWARE";
    connectionString = connectionString & "Database=COLDATA";
    connectionString = connectionString & "uid=reports";
    connectionString = connectionString & "pwd=reports";

    set ConnectDB = server.createObject("ADODB.Connection")
    connectDB.open connectionString

    set rs=Server.CreateObject("ADODB.recordset")
    sql="SELECT DISTINCT EOrigin FROM Ethnic_origin ORDER BY EId"
    rs.Open sql,conn
    EOrigin=request.form("EOrigin")

    %>

    <form method="post">
    Choose Country <select name="EOrigin">
    <% do until rs.EOF
    response.write("<option")
    if rs.fields("EOrigin")=EOrigin then
    response.write(" selected")
    end if
    response.write(">")
    response.write(rs.fields("EOrigin"))
    rs.MoveNext
    loop
    rs.Close
    set rs=Nothing %>
    </select>
    <input type="submit" value="Show customers">
    </form>

    <%
    if country<>"" then
    sql="SELECT EId,EOrigin FROM Ethnic_origin WHERE EOrigin='" & EOrigin & "'"
    set rs=Server.CreateObject("ADODB.Recordset")
    rs.Open sql,conn
    %>
    <table width="100%" cellspacing="0" cellpadding="2" border="1">
    <tr>
    <th>EId</th>
    <th>EOrigin</th>
    </tr>
    <%
    do until rs.EOF
    response.write("<tr>")
    response.write("<td>" & rs.fields("EId") & "</td>")
    response.write("<td>" & rs.fields("EOrigin") & "</td>")
    response.write("</tr>")
    rs.MoveNext
    loop
    rs.close
    conn.Close
    set rs=Nothing
    set conn=Nothing%>
    </table>
    <% end if %>

    </body>
    </html>

  2. #2
    Join Date
    Jan 2003
    Location
    New York
    Posts
    160
    Your Problem lies in your first slect statement

    sql="SELECT DISTINCT EOrigin FROM Ethnic_origin ORDER BY EId"

    You can not use "Order By" if that item is not selected
    real error message:
    ORDER BY items must appear in the select list if SELECT DISTINCT is specified.

    so you have 2 possiblities

    1 - eliminate order by
    sql="SELECT DISTINCT EOrigin FROM Ethnic_origin"

    2 - add Eid in selection
    sql="SELECT DISTINCT EOrigin,Eid FROM Ethnic_origin ORDER BY EId"
    Beyond Limitation

Posting Permissions

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