BrainDump
  Home arrow BrainDump arrow Page 2 - ADO Queries and Working with Recordsets
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Dedicated Servers 
Actuate Whitepapers 
Moblin 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
BRAINDUMP

ADO Queries and Working with Recordsets
By: James Payne
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 4
    2008-01-14

    Table of Contents:
  • ADO Queries and Working with Recordsets
  • Displaying Selected Records Using a Drop Down Menu
  • Sorting Records
  • How to Add a Record to Table
  • How To Delete a Record

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

    ADO Queries and Working with Recordsets - Displaying Selected Records Using a Drop Down Menu


    (Page 2 of 5 )

    One way that you can allow users to select data from your database is through the use of drop-down lists or menus. In the following program we will create a drop-down list containing names that appear in our VictimName column:


    <html>
    <body>

    <%
    set conn=Server.CreateObject("ADODB.Connection")
    conn.Provider="Microsoft.Jet.OLEDB.4.0"
    conn.Open(Server.Mappath("/db/chucknorrisvictims.mdb"))

    set rs=Server.CreateObject("ADODB.recordset")
    sql="SELECT DISTINCT VictimName FROM Victims"
    rs.Open sql,conn

    victimname=request.form("victimname")

    %>


    <form method="post">
    Please Select a Name from the List <select name="victimname">
    <% do until rs.EOF
    response.write("<option")
    if rs.fields("victimname")=victimname then
    response.write(" selected")
    end if
    response.write(">")
    response.write(rs.fields("victimname"))
    rs.MoveNext
    loop
    rs.Close
    set rs=Nothing %>

    </select>
    <input type="submit" value="Click for Victim Information">
    </form>

    <%
    if victimname<>"" then
    sql="SELECT VictimName,VictimInjury,HowItHappened FROM Victims WHERE victimname='" & victimname & "'"
    set rs=Server.CreateObject("ADODB.Recordset")
    rs.Open sql,conn
    %>

    <table width="100%" cellspacing="0" cellpadding="2" border="1">
    <tr>
    <th>VictimName</th>
    <th>VictimInjury</th>
    <th>HowItHappened</th>
    </tr>
    <%
    do until rs.EOF
    response.write("<tr>")
    response.write("<td>" & rs.fields("victimname") & "</td>")
    response.write("<td>" & rs.fields("victiminjury") & "</td>")
    response.write("<td>" & rs.fields("howithappened") & "</td>")
    response.write("</tr>")
    rs.MoveNext
    loop
    rs.close
    conn.Close
    set rs=Nothing
    set conn=Nothing%>

    </table>
    <% end if %>

    </body>
    </html>

    This program will create a drop down menu with a list of names from the Victims database, and a submit button. When the user selects a name from the list and clicks on the button, it will return that record and any data pertaining to it. Let's say the user selects the name Ralph Macchio. Here is the result:

     

    Ralph Macchio

    Broken Foot

    Ralph Macchio tried his crane kick on Chuck. When it connected to Chuck's powerful chest hairs, his foot shattered.

    More BrainDump Articles
    More By James Payne


       · Welcome to my article on ADO Queries. Prepare to have your puny mind blown as you...
       · Hi James, I'd like to see an article dealing with how to import attribute-centric...
     

    BRAINDUMP ARTICLES

    - Making Your First Active X Control in Visual...
    - Codes and Packages in Microsoft Project 2007
    - Windows 7: Rumors and Demos
    - XP SP3 Why Me?
    - Breaking Up Your Work in Microsoft Project
    - Breaking Work into Task-Sized Chunks
    - Putting Microsoft`s Worldwide Telescope Unde...
    - Handling Multiple Contracts with Indigo
    - Cleaning Out Your Data in XP
    - Multiple Service Contracts and Indigo
    - Cleaning Out Your Programs in XP
    - Handling Metadata with Indigo
    - Building Blocks for a WCF Service Web Site
    - Help! I Need Some Remote Assistance
    - Using Service Templates with Indigo





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway