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  
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? 
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 / 10
    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


    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!


    NEW! Cook up Web sites fast with CakePHP, Part 4: Use CakePHP&apos;s Session and Request Handler components

    CakePHP is a stable production-ready, rapid-development aid for building Web sites in PHP. This "Cook up Web sites fast with CakePHP" series shows you how to build an online product catalog using CakePHP.
    FREE! Go There Now!


    NEW! Discovering the value of WebSphere Process Server

    WebSphere Process Server delivers a unique integration framework that simplifies existing IT resources. Often, as IT assets grow to support business demand, so too does their complexity and manageability. In this webcast, we’ll discuss how WebSphere Process Server helps deliver an SOA infrastructure that provides a common model to orchestrate, mediate, connect, map, and execute the underlying IT functions. Discover how WebSphere Process Server simplifies integration of business processes by leveraging existing IT assets as reusable services without the complexities of traditional integration methodologies.
    FREE! Go There Now!


    NEW! Download DB2 Express-C 9.5

    Visit IBM developerWorks to download IBM DB2 Express-C 9.5, a no-charge version of DB2 Express 9 database server. DB2 Express-C offers the same core data server base features as other DB2 Express editions and provides a solid base to build and deploy applications developed using C/C++, Java, .NET, PHP, and other programming languages.
    FREE! Go There Now!


    NEW! IBM Rational ClearCase Innovator's Series

    Learn from the best! Find out how developers use Rational ClearCase to be more flexible, innovative and deliver higher quality code in the Rational ClearCase Power Users eKit. This complimentary eKit provides a collection of materials, like articles, whitepapers, and demos that can help you become a power user of Rational ClearCase.
    FREE! Go There Now!


    NEW! Rational Modeling Extension for Microsoft.Net

    Rational Modeling Extension for Microsoft .NET enhances usability for code generation supporting a more intelligent refactoring. The latest enhancements enable organizations with Java and .NET systems and software development maintain architectural integrity across heterogeneous platforms.
    FREE! Go There Now!


    NEW! Rational Talks to You: Grady Booch on Architecture

    Join this Rational Talks to You teleconference on November 29 at 1:00 pm ET to participate in an interactive discusssion with Grady Booch around architecture and reuse. Get your questions answered!
    FREE! Go There Now!


    NEW! Trial download: IBM Informix Dynamic Server Express Edition V11.0

    Informix Dynamic Server (IDS) Express Edition offers outstanding online transaction processing (OLTP) database performance, while helping to simplify and automate many of the tasks associated with deploying databases for small business applications. IDS 11 further extends the ease of management and applications integration with the Admin API and Scheduler, high availability with Continuous Log Restore for backup server recovery in case of a primary server failure, and column level encryption to protect personal and company private data.
    FREE! Go There Now!


    NEW! Try the IBM SOA Sandbox for People

    Visit IBM developerWorks to try the IBM SOA Sandbox for people. The SOA Sandbox for people provides a trial environment with the necessary tooling and components required to enable consistent human and process interaction and collaboration, showing how you can improve user experience and business productivity.
    FREE! Go There Now!


    NEW! Using Rational Business Developer to enhance your developer productivity

    Join this Rational Talks to You teleconference, to hear how Enterprise Generation Language (EGL) eliminates the need for tedious and error-prone low level coding, so developers can focus on business requirements. EGL extends the Rational software development platform with a simplified programming language that enables developers who have little or no experience with Java, Web technologies or Service Oriented Architecture, to create enterprise-class applications and services quickly and easily. It also allows developers who may have little or no mainframe programming experience to quickly create traditional mainframe components.
    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!



    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-2009 by Developer Shed. All rights reserved. DS Cluster 6 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek