47,379 Members
2 added today
492,145 Resources
89 added today

All Devdex   All Gurus  

Just think, 101 forms and 1 database script in ASP!
Author: Matt Burnett
Rating:
Visits: 11210

Discuss in Newsgroups

Page:

Imagine adding web forms that will automatically be ready for use with a database. This is not an IDE or simple trick. I think this article will help programmers expand their knowledge of web architecture, as they have not been presented with a different way to handle web forms that present and update a database in ASP.

In many cases, web programmers present a web page and ‘fill’ it with information from the database. If the data is to be updated (inserted or removed), then the data is presented in a form and ‘submitted’ to a server script to be processed. This method is ok, but assumes a 1 to 1 relationship between the each form and server processing script. Our goal is ‘many’ web forms and one processing script.

First, in designing the web architecture for integrating a database, we assume a single data source (Conn).

To keep this straightforward, we have a standard ‘web form’ defining some input variables. Here is our ‘web form’:

  1. In ALL web forms, take a recordset and output to a form object using HTML Textboxes to display the data. In the name property of the textbox put "name=<%=rs("columnName").name%>". In the value property of the same textbox write "value=<%=rs("columnName").value%>".
  2. Insert a ‘hidden’ input type in the form. The name property is ‘Name=xSqlCommand’ and value=’INSERT’. This represents the sql command you wish to execute. Examples are INSERT, UPDATE, and DELETE.
  3. Insert a ‘hidden’ input with the name property ‘name=xTABLE’ and value=’Tablename’. The Tablename is the database table from which the recordset originates. Often, TableName is server-side as it was used in the SQL statement to derive the recordset.
  4. For UPDATE and DELETE statements, insert another ‘hidden’ input type in the form, ‘name=xPrimaryKey’ and value=’RowPrimaryKeyValue’. Often the FieldName primary key is ID or nameID or something like that.
  5. For UPDATE and DELETE statements, insert another ‘hidden’ input type in the form, ‘name=xPrimaryKeyFieldName’ and value=’strPrimaryKFieldName’. The string value of the primary key column name.
  6. Submit all web forms to the same ASP script. I.e. ACTION=udpatedb.asp

Here is the server script. In the method below *NOTE* the little ‘x’ that will tell us that the requested value is not a database field name. The purpose of the ‘x’ is to separate our database fields from other inputs. Other inputs can be security, user, or application information used in script processing.

An additional comment before the code: This script requires you to have a solid understanding of programming and will NOT be a simple ‘cut and paste’. Read and make customizations to fit your software. This script has worked extremely well for me and I hope that you can make good use of it.


Next Page >>

Visitor Comments

Michael Paul Regardless of security, this is still a very simpl...
Ryan Wheeler Why no mention of the flaws of this approach - no ...
Elliot Grossman This is a great way to create forms. It is well wr...

 

Rate this Article







	
	
	



Credit Card Payment Control
Supports over 25 companies
Managed ASP.NET Solution
Direct Processor Support

ASP ArticlesThis category has been added to your weekly newsletter
ASP Web Sites
ADSI & WSH BooksThis category has been added to your weekly newsletter
FREE ComponentsThis category has been added to your weekly newsletter
ASP EventsThis category has been added to your weekly newsletter
ASP HeadlinesThis category has been added to your weekly newsletter

CSharp ArticlesThis category has been added to your weekly newsletter
C# Web SitesThis category has been added to your weekly newsletter

SQL ArticlesThis category has been added to your weekly newsletter
SQL Events
SQL HeadlinesThis category has been added to your weekly newsletter
SQL Jobs

Jobs in CaliforniaThis category has been added to your weekly newsletter

XML ArticlesThis category has been added to your weekly newsletter
XML BooksThis category has been added to your weekly newsletter
XML Web Sites
XML Tutorials

free asp host

"Alex Homer"This search has been added to your weekly newsletter

Edit My Favorites Edit Profile & Favorites

Web Programming

 




Developersdex Home | ASP | C# | SQL | VB | XML | Gurus
Add Your Link | Add Your Code | FAQ | Advertise | Link To Us | Contact Us |
Copyright © 2008 Developersdex™. All rights reserved.