BrainDump
  Home arrow BrainDump arrow 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  
Silverlight  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
ASP Web Hosting  
ASP.NET Web Hosting 
Windows Web Hosting
 
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


    ADO Queries and Working with Recordsets


    (Page 1 of 5 )

    Back in late November of last year I wrote an article that covered ADO for the beginner. At that time I left off with ADO connections, recordsets, and how to display them. Finally returning to the topic after a spell, in this episode we will discuss queries, sorting, and a few other tricks with ADO.

     If you'd like to review before we proceed, you can read the previous tutorial. Go ahead, I'll wait. Or if you want a quicker review, we'll pick up at the very end of it, where I showed you the Victims table from the chucknorrisvictims database:

     

    VictimName

    VictimInjury

    HowItHappened

    Ralph Macchio

    Broken Foot

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

    Jackie Chan

    Forced to work with Chris Tucker the rest of his life

    Chuck Norris punched Jackie Chan so hard he went from an A-list actor to a B-list actor

    Death

    Granted Eternal Life

    Death came for one of Chuck's victims before he was finished with him, so Chuck did a roundhouse kick and hit Death so hard not only did he become a living being, but he gained immortality as well.

    Displaying Selected Records

    We can use SQL to create queries in ADO when we want to see data that matches a certain criteria. Let’s say we are working with our chucknorrisvictims database and we want to extract everyone whose name begins with “J”:


    <html>

    <body>

    <%

    set conn=Server.CreateObject("ADODB.Connection")

    conn.Provider="Microsoft.Jet.OLEDB.4.0"

    conn.Open "c:/webdata/chucknorrisvictims.mdb"

    set rs=Server.CreateObject("ADODB.recordset")

    sql="SELECT VictimName, VictimInjury FROM Victims

    WHERE VictimName LIKE 'J%'"

    rs.Open sql, conn

    %>

    <table border="1" width="100%">

    <tr>

    <%for each x in rs.Fields

    response.write("<th>" & x.name & "</th>")

    next%>

    </tr>

    <%do until rs.EOF%>

    <tr>

    <%for each x in rs.Fields%>

    <td><%Response.Write(x.value)%></td>

    <%next

    rs.MoveNext%>

    </tr>

    <%loop

    rs.close

    conn.close%>

    </table>

    </body>

    </html>

    This would result in the following:

     

    VictimName

    VictimInjury

    Jackie Chan

    Forced to work with Chris Tucker the rest of his life

    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

    - Firefox on Windows Mobile
    - Microsoft`s Sneaky Firefox Add-On Installati...
    - Microsoft`s Answer to Google Search - Bing
    - Doing Statistical Analysis with MS Excel
    - Extracting Google-Indexed Web Site Pages Usi...
    - Advanced String Manipulation Using MS Excel
    - Using Goal Seek and Solver in MS Excel
    - Internet Explorer 8: A Hands-on View
    - Tools for Beginning Game Developers
    - XAMPP: Tips for Running an Apache/MySQL Serv...
    - Improving Your Visual Studio Workspace
    - A Look at Microsoft`s Mobile Operating System
    - Microsoft Internet Explorer 8: Mixed Reactio...
    - Configuring WSUS 3.0 on Windows Server 2008
    - Migrating to Windows Server 2008





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
    Stay green...Green IT