Database Code
  Home arrow Database Code arrow How to update records using ASP and and fo...
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 and formatted Sql
By: aspfree
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 3 stars3 stars3 stars3 stars3 stars / 12
    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 Formatted SQL


     
    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.

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

    'Declare all local variables

    dim conn
    dim rs
    dim strconn
    dim strsql

    strsql = ""

    'set connection string to local variable

    strconn = "DRIVER=Microsoft Access Driver (*.mdb);DBQ=" & Server.MapPath("adoandsqladd.mdb")
    set conn = server.createobject("adodb.connection")
    conn.open strconn
    'Use the execute method of the connection object the insert the record
    'build the sql statement based on the input from the form

    For x = 1 to 5
    strSQL = "UPDATE tblUpdateSQL " & _
    "SET tblUpdateSQL.FirstName = '" & request("FirstName" & x) & "', " & _
    "tblUpdateSQL.lastName = '" & request("LastName" & x) & "' " & _
    "WHERE (((tblUpdateSQL.id)=" & x & "))"
    conn.execute(strSQL)

    Next

    conn.close
    set conn = nothing

    %>

    <% = "Your record has been added" %>

    <p><br>

    </p>

    <p><a href="updatesql.asp">Click here to return to the start page of the demo</a></p>

    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! Download the free Web Application Security eKit

    Discover how IBM Rational AppScan Standard Edition can help you detext vulnerabilities in your web applications in the Web Application Security eKit. IBM Rational AppScan is a leading suite of automated web application security solutions that scan and test for common Web application vulnerabilities. The new Web Application Security eKit provides you with valuable resources, including white papers, demos, and additional information on the benefits of testing your Web applications.
    FREE! Go There Now!


    NEW! Maintaining QoS and Process Integrity in an SOA Environment

    This webcast outlines the best practices that must be instituted to gain the maximum benefit from SOA while maintaining high quality of service. Whether you are deploying new applications or managing and monitoring your existing infrastructure, learn how you can ensure high quality of services with SOA based solutions from IBM. All registrants who attend this live Web Seminar will receive complimentary access to a white paper titled “Maintaining QoS in an SOA Environment”.
    FREE! Go There Now!


    NEW! Trial download: IBM Rational Method Composer V7.2

    Get a free trial download of the latest version of IBM Rational Method Composer V7.2 which helps you deliver customized yet consistent process guidance to your project teams and IT organization, and includes the latest version of IBM Rational Unified Process (RUP), which has provided process guidance to teams since 1996.
    FREE! Go There Now!


    NEW! Trial download: IBM Rational Performance Tester V7.0.1

    Get a free trial download of the latest version of IBM Rational Performance Tester V7.0.1, a load and performance testing solution for teams concerned about the scalability of their Web-based applications. Combining multiple ease-of-use features with granular detail, Rational Performance Tester simplifies the test-creation, load-generation and data-collection processes that help teams ensure the ability of their applications to accommodate required user loads.
    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! Try the IBM SOA Sandbox for Process

    Visit IBM developerWorks to try the IBM SOA Sandbox for process. The SOA Sandbox for process focuses on providing a trial environment with the necessary tooling and components required to gain a better understanding of business processes and how to best improve existing business processes to derive value quickly.
    FREE! Go There Now!


    NEW! Webcast: Accelerating Software Innovation with System z

    Attend this launch webcast with Scott Hebner, Vice President of IBM Rational Marketing and Strategy, where he will overview Rational’s new offerings and programs to help customers accelerate software innovation on System z. He will discuss how these solutions help organizations extend their core business processes toward modern architectures such as SOA and web technologies to deliver business improvements that stand the test of time.
    FREE! Go There Now!


    NEW! Webcast: Application security testing and Web compliance

    Join the IBM Watchfire team for an informative discussion on techniques and best practices to proactively manage Web application security and how to effectively build application security testing into the software development lifecycle (SDLC). In this Software Delivery Platform webcast you will learn: How to better understand potential web application security vulnerabilities, best practices and how to effectively integrate application security testing into the software development lifecycle, the importance of detecting and removing software vulnerabilities during application development.
    FREE! Go There Now!


    NEW! Webcast: Quickly provide customized, integrated user interfaces with Lotus Notes 8

    IBM Lotus Notes 8 provides a wide range of developers the ability to provide customized, integrated user interfaces via composite applications and via custom sidebar and toolbar plug-ins. This webcast provides you with tips and techniques to use with out-of-the-box capabilities of Lotus Notes 8, and survey how you can share useful components within your own company and within a larger community.
    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...
    - Two combos, one textbox example
    - ADO Recordset Paging
    - SQL Server Database Creator - .NET Version
    - Getting A List of Tables From SQL Server
    - Discussion & Listserv Module by Mike Eck...





    © 2003-2010 by Developer Shed. All rights reserved. DS Cluster 2 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek