Database Code
  Home arrow Database Code arrow How to update records using ASP and ADO
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 
IBM developerWorks
 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? 
DATABASE CODE

How to update records using ASP and ADO
By: aspfree
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 9
    1999-09-01

    Table of Contents:

    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

    Updating Records to a Database using ADO(ActiveX Data Objects)


     
    All ASP Code is in RED
    'This page doesn't use a session variable so for performance reasons I set the two directives. 
    'By Setting the EnableSessionState you save the asp.dll from making a call to the MTS to check
    'for Session variables used by this page

    <%@ Language = "VBScript" @ ENABLESESSIONSTATE=False %>
    <%
    'Declare all local variables

    dim conn
    dim rs
    dim strsql
    dim strconn
    'Set local variable to the connection string and open the connection
    strconn = "DRIVER=Microsoft Access Driver (*.mdb);DBQ=" & Server.MapPath("adoandsqladd.mdb")
    set conn = server.createobject("adodb.connection")
    conn.open strconn
    'Set local recordset variable equal to rs
    set rs = server.createobject("adodb.recordset")
    'Sets the sql query that determine what records get brought back to the asp page.
    'This could easily be change to a very specific set of fields or instead of using a ORDER BY statement
    'Using a  WHERE statement to determine what records get selected IE(WHERE tblUPDATEADO.id=1)

    strsql = "SELECT * FROM tblUpdateADO ORDER BY id"
    rs.open strsql, conn
    %>

    <html>
    <head>
    <title>signon</title>
    </head>
    <body>
    <h3 align="center">Update w/ADO example</h3>
    <td width="10%"><form method="post" name="form1" action="updateado2.asp">
    <table>
    <%
    'Writes out the records, again this could just writing out one record just take away the DO While LOOP


    x = 1
    rs.movefirst
    Do While NOT rs.EOF
    %>

    <tr><td><strong>First Name</strong></td><td>
    <input type="text" size="10" name="FirstName<%= x %>" value="<% = rs("FirstName")%>"></td>
    <td><strong>Last Name</strong></td><td>
    <input type="text" size="10" name="LastName<%= x %>" value="<% = rs("LastName")%>"></td>
    </tr>
    <%
    x = x + 1
    'Don't forget to move the recordset to the next record or your going to have an infinate loop
    'Trust me this statement I always forget!

    rs.movenext
    Loop
    %>

    <td><input type="Submit" value="Submit Update Example" name"b1"> </font>
    </form>
    </td></tr>
    </table>
    </center></div>
    </body></html>

    Page 2 the page actually re-submits the information back to the database  Here is the code that is used to update the information on the demo.

    'This page doesn't use a session variable so for performance reasons I set the two directives. 
    'By Setting the EnableSessionState you save the asp.dll from making a call to the MTS to check
    'for Session variables used by this page

    <%@ Language = "VBScript" @ ENABLESESSIONSTATE=False %>
    <%

    'Declare all local variables

    dim conn
    dim rs
    dim strID
    'Set local variable to the connection string and open the connection
    strconn = "DRIVER=Microsoft Access Driver (*.mdb);DBQ=" & Server.MapPath("adoandsqladd.mdb")
    set conn = server.createobject("adodb.connection")
    conn.open strconn
    'Set record set object and opens the table that will update the records
    set rs = server.createobject("adodb.recordset")
    rs.open "tblUpdateADO", conn, 2, 2
    rs.movefirst
    for x = 1 to 5
    rs("FirstName") = request("FirstName" & x)
    rs("LastName") = request("LastName" & x)
    rs.update
    rs.movenext
    Next
    rs.movefirst
    %>

    <html>
    <head>
    <title>Results of the Update ADO Demo</title>
    </head><body>

    <table BORDER="0">
    <% x = 1
    rs.movefirst
    Do While NOT Rs.EOF
    %>

    <tr><td><strong>First Name</strong></td><td><% = rs("FirstName")%></td><td>
    <strong>Last Name</strong></td><td><% = rs("LastName")%></td></tr>
    <%
    x = x + 1
    rs.movenext
    Loop
    %>

    </table>

    <p><a href="updateado.asp">Click here to go back to the start page</a></p>
    </body>
    </html>
    <%
    set rs= nothing
    set conn = nothing
    %>
    Good Luck!!

    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.

    More Database Code Articles
    More By aspfree

     

    IBM® developerWorks developerWorks - FREE Tools!


    IBM – Taking Web 2.0 to Work

    You'll get answers to many questions and more from David Barnes, Lead Evangelist for IBM Emerging Internet Technologies. David will discuss aspects of Web 2.0 that bring value to corporations, academia, and government. He'll also discuss IBM's vision around Web 2.0, including the importance of remixability and consumability. The discussion will culminate with examples of various IBM Software Group solutions you can use to get ahead of the Web 2.0 adoption curve.
    FREE! Go There Now!


    NEW! Best practices for software analysis: An introduction to the IBM Rational Software Analyzer application

    This whitepaper presents the benefits of successfully introducing static analysis into your organization using IBM Rational Software Analyzer. Additionally, it identifies some common pitfalls that can hinder the effective use of static analysis tooling as well as presents 10 simple strategies designed to help you quickly realize the value of static analysis using Rational Software Analyzer.
    FREE! Go There Now!


    NEW! Don't wait! Try the Rational Application Developer (RAD) v7.5 open beta code today

    Download the Rational Application Developer (RAD) v7.5 open beta code and start developing applications for the JEE5 standard which features EJB3.0, JPA, JSF 1.2, JSP 2.1 and Servlet 2.5 standards. When you use this beta you will see how you can increase developer productivity for already existing applications with improved support for refactoring, as well as adding new features to existing applications. In addition, the beta provides tooling for JD Edwards, Oracle, SAP, Siebel and PeopleSoft to improve the developer productivity with these enterprise systems.
    FREE! Go There Now!


    NEW! Evaluate IBM Rational Developer for System i V7.1

    Download a free trial version of IBM Rational Developer for System i V7.1, which provides a complete development environment for traditional i5/OS application development. IBM Rational Developer for System i is a new eclipse-based workstation offering for i5/OS application development that provides a comprehensive Integrated Development Environment for edit/compile/debug of traditional RPG/COBOL/C/C++ i5/OS applications.
    FREE! Go There Now!


    NEW! Hello World: WebSphere Service Registry and Repository

    Manage, govern, and share services across your organization by using WebSphere Service Registry and Repository. Follow the hands-on exercises to learn how to navigate the Web interface to publish, find, reuse, and update services.
    FREE! Go There Now!


    NEW! Info 2.0: Harnessing the power of Web 2.0 and Enterprise Mashups

    Listen to this webcast to get an overview of Info 2.0 and a technical demo of how to quickly build an enterprise mashup. IBM's Info 2.0 technology leverages emerging Web 2.0 technologies such as mashups, feeds, AJAX, and JSON in order to simplify assembly of information using feeds and services. Come learn about the technical elements of Info 2.0 including the Feed Generation framework, Mashup Engine, and mashup assembly components. Learn how to pull information from databases, departmental information, and the Web to create mashups critical to your company’s success. We will also discuss best practices to help you get started.
    FREE! Go There Now!


    NEW! Rational Asset Manager eKit

    Learn how to do more with your reusable assets with the free Rational Asset Manager eKit. The eKit includes demos on how Rational Asset Manager tracks and audits your assets in order to utilize them for reuse. Plus you’ll find white papers and a Webcast that discuss the challenges of a Service Oriented Architecture and how Rational Asset Manager can provide quick and effective solutions.
    FREE! Go There Now!


    NEW! The role of integrated requirements management in software delivery

    This paper is about the critical role that a discipline called integrated require­ments management can play in helping to ensure that your business goals and IT investments are continuously aligned—whether you are sourcing, integrat­ing, building or maintaining software. It also looks at ways that automated IBM Rational® products can work together to help you use requirements in the very best way.
    FREE! Go There Now!


    NEW! Webcast: What is new in Viper 2 for developers?

    Viper 2 brings a great value to developer communities including SQL, XML, PHP, Ruby, .NET and Java. You probably already know that DB2 Express-C is free for developers to develop, deploy and distribute. Viper 2 provides a variety of means that help move your application from the development stage to deployment more rapidly. This webcast shows how to best utilize the latest tools available for developing DB2 applications.
    FREE! Go There Now!


    NEW! Whitepaper: Achieving consistency between business process models and operational guides

    Explore how Rational and WebSphere software enable enterprise documentation in SOA environments. Specifically, a new integration between IBM WebSphere® Business Modeler and IBM Rational® Method Composer software can help technical writers more easily keep enterprise operations manuals in sync with changes that are made to business processes, resulting in more accurate and timely documentation that benefits the entire enterprise.
    FREE! Go There Now!



    All FREE IBM® developerWorks Tools!

    DATABASE CODE ARTICLES

    - Deployment of the MobiLink Synchronization M...
    - MobiLink Synchronization Wizard in SQL Anywh...
    - Finding Matching Records in Data Access Pages
    - Using the AccessDataSource Control in VS 2005
    - A Closer Look at ADO.NET: The Command Object
    - A Closer Look at ADO.NET: The Connection Obj...
    - Using ADO to Communicate with the Database, ...
    - Code Snippets: Counting Records
    - Constraints In Microsoft SQL Server 2000
    - Multilingual entries into a DB and to be dis...
    - Getting A List of Tables From SQL Server
    - SQL Server Database Creator - .NET Version
    - ADO Recordset Paging
    - Two combos, one textbox example
    - Discussion & Listserv Module by Mike Eck...





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