BrainDump
  Home arrow BrainDump arrow Page 5 - 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 
VeriSign Whitepapers 
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

    Free Web 2.0 Code Generator! Generate data entry and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!

    ADO Queries and Working with Recordsets - How To Delete a Record


    (Page 5 of 5 )

    The first step in allowing a user to delete a record is to display our table of data, like so:


    <html>

    <body>

    <%

    set conn=Server.CreateObject(“ADODB.Connection”)

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

    conn.Open “c:/website/chucknorrisvictims.mdb

    set rs=Server.CreateObject(“ADODB.Recordset”)

    rs.Open “SELECT * FROM Victims”,conn

    %>

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

    <tr>

    <%

    for each x in rs.Fields

    response.write(“<th>” & ucase(x.name) & “</th>”)

    next

    %>

    </tr>

    <% do until rs.EOF %>

    <tr>

    <form method=”post” action=”sampledelete.asp”>

    <%

    for each x in rs.Fields

    if x.name=”VictimName” then%>

    <td>

    <input type=”submit” name=”VictimName” value=”<%=x.value%>”>

    </td>

    <%else%>

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

    <%end if

    next

    %>

    </form>

    <%rs.MoveNext%>

    </tr>

    <%

    loop

    conn.close

    %>

    </table>

    </body>

    </html>

    The above code displays the data in our database. If the user clicks on any of the Victim Names, they will be taken to an ASP page where they can opt to delete the record. Here is the code for that page:


    <html>

    <body>

    <%

    set Conn=Server.CreateObject(“ADODB.Connection”)

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

    conn.Open “c:/website/chucknorrisvictims.mdb

    vic=Request.Form(“VictimName”)

    if Request.Form(“VictimName”)=”” then

    set rs.Server.CreateObject(“ADODB.Recordset”)

    rs.open “SELECT * FROM Victims WHERE VictimName='” & vic & “'”,conn

    %>

    <form method=”post” action=”sampledelete.asp”>

    <table>

    <%for each x in rs.Fields%>

    <tr>

    <td><%=x.name%>” value=”<%=x.value%>”></td>

    <%next>

    </tr>

    </table>

    <br /><br /><br />

    <input type=”submit” value=”Click to Delete”>

    </form>

    <%

    else

    sql=”DELETE FROM Victims”

    sql=sql & “WHERE VictimName='” & vic & “'”

    on error resume next

    conn.Execute sql

    if err<>0 then

    response.write(“You do not have permission to delete”>

    else

    response.write(“The Record “ & vic & “ has been deleted.”)

    end if

    end if

    conn.close

    %>

    </body>

    </html>

    This program will display the record the user chose from the previous page, and give them the option to delete the record. If they do not have permission, they will receive an error message; otherwise the record will be deleted and they will receive a message saying the record has been deleted.

    Well that's it for this episode. In the next article we will learn how to update a database record, and start learning about ADO Objects.

    Till then...


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

       · 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

    - 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
    - Windows XP Tips for Task Manager

    SunQuest




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