My purpose of this example is to show how to get records from an html form and submit that form to an ASP page. This ASP page will then use ADO to enter the records into the database When I started doing ASP, getting records from an ASP page to a database was my 1st thing I wanted to do. I quickly discovered there was a few ways you could do that. This example uses ADO to take data from a html form and submit to an ASP page that processes the data using ADO. A good book on ADO is by Wrox Press called ADO 2.0 Programmer's reference.) Below is the code I used in this example, go ahead and try entering something in.
1st page the Input form- This is just a standard html Input form
<html><head>
<title>ADO add record example</title>
</head>
<body>
<h3 align="center">ADO example</h3>
<td width="424"><form method="post" name="form1" action="addrecordado2.asp">
<p><strong>First Name</strong><br>
<input type="text" size="40" name="FirstName"><br>
<strong>Last Name</strong><br>
<input type="text" size="40" name="LastName"><br>
<strong>FavoriteColor</strong><br>
<input type="text" size="40" name="FavoriteColor"><br>
<p><input type="Submit" value="Submit New Example" name"b1"> </font></p>
</form>
</td>
</tr>
</table>
</center></div>
</body></html>
2nd The ASP page that process the information
<%@ Language = "VBScript"%>
<%
'Declare all local variables
dim conn
dim rs
dim strID
dim strconn
'set a local variable to my DSN-less connection String
strconn = "DRIVER=Microsoft Access Driver (*.mdb);DBQ=" & Server.MapPath("adoandsqladd.mdb")
'Create the Connection object
set conn = server.createobject("adodb.connection")
conn.open strconn
'Create the recordset object
set rs = server.createobject("adodb.recordset")
'This statement opens the table so we can add a record notice the addnew
'The 2, 2 is how the table is opened there are many ways it can be opened
rs.open "tblAdoAdd", conn, 2, 2
'Use the addnew method of the recordset object to add a record
rs.addnew
'Set the table column = to my input text box from my form
rs("FirstName") = request("FirstName")
rs("LastName") = request("LastName")
rs("FavoriteColor") = request("FavoriteColor")
rs.update
'I do a movelast here to get the ID that is automatically generated
'I also set the value to a local variable so I can write out to the database
rs.movelast
strID = rs("ID")
%>
<html>
<head>
<title>sign on summary</title>
</head>
<body>
<TABLE BORDER=1>
Your Record # is:<% = strID %>
Your First Name is <% = request("FirstName") %>
Your Last Name is <% = request("LastName") %>
Your Favorite Color is <% = request("Favoritecolor") %>
</body></html>
<%
'Always! Always set your objects to nothing. This clears them out of servers memory
'Your network admins will like this
set rs= nothing
set conn = nothing
%>
| 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
developerWorks - FREE Tools! |
As businesses grow increasingly dependent upon Web applications to provide services to customers, employees and partners, these complex applications become more difficult to secure. Although traditional security solutions protect Internet infrastructure layers, they do not guard against HTTP and HTML attacks. Many organizations that conduct security testing still deploy applications that allow attackers to manipulate their logic and wreak havoc on their business. To mitigate this risk, development and delivery teams must address Web application security throughout the lifecycle, addressing the many layers detailed in this paper. FREE! Go There Now!
|
|
|
|
You probably have thousands of lines of COBOL code loaded with business intelligence and being used to run your business, along with an army of developers maintaining these applications. Learn how to prepare your applications and developers so you can keep that competitive edge and move to a service-oriented architecture with the IBM Rational Enterprise Modernization solutions. Replay is available for 9 months. FREE! Go There Now!
|
|
|
|
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!
|
|
|
|
Visit IBM developerWorks to download a free trial version of IBM Rational Business Developer V7.1. Rational Business Developer offers rapid and simplified development of business applications and services through Enterprise Generation Language (EGL) tools, generating Java or mainframe solutions while shielding developers from technical complexities. FREE! Go There Now!
|
|
|
|
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!
|
|
|
|
Regression testing -- in which code is thoroughly tested to ensure that changes have not produced unexpected results -- is an important part of any development process. But many testing environments neglect the terminal-based applications that still form the backbone of many industries. In this tutorial, you'll learn how the Rational Functional Tester Extension for Terminal-Based Applications works with other Rational Functional Tester to help test terminal-based applications quickly and easily. FREE! Go There Now!
|
|
|
|
Try the latest version of IBM Rational Manual Tester V7.0.1 by downloading a free trial from IBM developerWorks. This manual test authoring and execution tool promotes test step reuse to reduce the impact of software change on testers and business analysts and addresses the needs of teams performing at least a portion of their testing manually. FREE! Go There Now!
|
|
|
|
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!
|
|
|
|
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!
|
|
|
|
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!
|
|
|
|
All FREE IBM® developerWorks Tools! |