ASP,Since,especially,good,reading,writing,dat
Quick Search for:  in language:    
ASP,Since,especially,good,reading,writing,dat
   Code/Articles » |  Newest/Best » |  Community » |  Jobs » |  Other » |  Goto » | 
CategoriesSearch Newest CodeCoding ContestCode of the DayAsk A ProJobsUpload
ASP/ VbScript Stats

 Code: 144,429 lines
 Jobs: 168 postings

 
Sponsored by:

 

You are in:

 
Login


 

 


Latest Code Ticker for ASP/ VbScript.
Click here to see a screenshot of this code!Ping in ASP
By Michele_Garneri on 10/28

(Screen Shot)

Embed Real Player Object
By Ziae Mousavi m. on 10/27


Set Country --> Combobox
By Hohl David on 10/27


Client Side Sorting of records
By Ravi Rajan on 10/26


Recordset paging with images
By Ravi Rajan on 10/26


Click here to see a screenshot of this code!Online photo catalogue VBScript 2.1
By Ivan Loire on 10/26

(Screen Shot)

GPS 1.4 WYSIWYG
By Guo Xu on 10/25


Click here to see a screenshot of this code!A Network Monitor tool from ActivXperts Software Inc.
By Freddy Hofstadt on 10/25

(Screen Shot)

Socket samples based on Winsock, TCP/IP and client/server communication
By Ronny Bright on 10/25


Click here to put this ticker on your site!


Add this ticker to your desktop!


Daily Code Email
To join the 'Code of the Day' Mailing List click here!





Affiliate Sites



 
 
   

Database Basics: Part I

Print
Email
 

Submitted on: 5/16/2000 1:00:18 PM
By: Kathi O'Shea  
Level: Advanced
User Rating: By 9 Users
Compatibility:ASP (Active Server Pages), VbScript (browser/client side)

Users have accessed this article 15797 times.
 
 
     Since ASP is especially good at reading and writing to databases, let's start with a very simple database and scripts that we'll eventually build into a guestbook... Reprinted with permission from http://www.web-savant.com/users/kathi/asp

 
 
Terms of Agreement:   
By using this article, you agree to the following terms...   
1) You may use this article in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.   
2) You MAY NOT redistribute this article (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
3) You may link to this article from another website, but ONLY if it is not wrapped in a frame. 
4) You will abide by any additional copyright restrictions which the author may have placed in the article or article's description.
For now, start with a database with Name, City, State, and Country. I've built my database with MS Access, but you can use any ODBC-compliant database you'd like. First, follow the link below to view the ASP page, then click on "view code" to see the code behind the page. If you'd like, you can download the MS Access database and scripts. (Zip format, 18K)

View Working Sample      View Code

Modifying Records
Now that you've seen how simple it is to display contents of your database, let's go to the next step - modifying the records that exist in the database. We'll start with a very simple page that queries the database and displays a summary of the contents (in this case, we'll just list the names), and then allows you to click on a listing to modify the information contained in that record.

View working Sample      View Code        Top of Page

Adding New Records
The above works just fine if you have records in the database. But what if you want to add records? No problem! First we'll create a regular html form that passes the variables to a script for processing, then the script itself that adds the new record to the database. In this script, we'll also introduce simple form validation prior to processing.

View Working Sample      View Code        Top of Page

Deleting Records
The last thing we'll need to do is add a provision to delete unwanted records from our database. Please note that in the example, all records can be deleted except for one - I wanted to make sure that there would be at least one record in the database at all times for demonstration purposes.

View Working Sample      View Code        Top of Page

Submitting Scripts to Themselves
Sometimes its advantageous to use a single script for multiple purposes. But how do we accomplish this? By using scripts that submit back to themselves, using some sort of "flag" to determine what actions need to be performed. Let's use our database scripts as an example. We had an html form for entering information into a new record, which submits to a separate ASP script to actually insert the record into the database. We'll combine both files into a single script that displays the form if there's no flag passed and inserts the record into the database if another flag value is passed to the script. Just for fun we'll even add a routine to display the information for verification before its submitted - and use a flag for that, too. Our "flags" and values could be just about anything you'd like, but to keep things very simple, we'll use "Flag" and make the values numeric.

View Working Sample      View Code        Top of Page

Paging Through Recordsets
Now that we've gone throught the basics of database access, let's go a step further. The sample script above for viewing a database is fine if you only have a few records. Imagine, however, that you have several hundred - or even thousands - of records. Clearly the above script won't work. We will need to add some sort of paging mechanism so we can navigate through our recordset. The key to this is built-in features of ADO: .RecordCount, .PageSize, and .AbsoluteCount. We'll use these features to figure out how many records are in the recordset, specify how many records you want per page, and which page of the recordset we want to work with. This is also an example of a script that submits to itself; in this case the script acts upon the page number that's passed to it. If there is no page number passed to the script, the script sets the page number to 1. The sample script is part of the Free Guestbook download.

View Working Sample      View Code        Top of Page

Summary
In this section, we've learned how to connect to a database, perform a simple query, and display the contents on a dynamically generated web page. We've also learned how to modify records in the database, and how to delete records. Now that we've got the basic skills to read and write to a database, its not much of a jump to extend these skills to writing a database-generated guestbook. The next page will show you how...

  Top of Page       Building a Guestbook


Other 6 submission(s) by this author

 

 
Report Bad Submission
Use this form to notify us if this entry should be deleted (i.e contains no code, is a virus, etc.).
Reason:
 
Your Vote!

What do you think of this article(in the Advanced category)?
(The article with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor See Voting Log
 
Other User Comments
5/17/2000 6:12:07 PM:k41221
Thank you.... Very Helpful
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
12/10/2000 12:57:14 AM:Hamlet
Hey, I only wondered how I can set up a connection string without the use of an SQL Server? Because I don't have one. Please anybody help me! E-mail me at: al932151@academ01.ags.itesm.mx
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
8/29/2001 5:45:47 PM:Blake Pell
This is serving as an excellent learning tool for me with ASP to database applications. 5 globes!
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
8/27/2002 2:16:52 AM:kinglonsome
it is great pleasure to see this lovely article, but unfortunately when I tried on first script there were plenty blender mystakes. Like in three statment command Response.write was missing, and uid, pwd fields in connection string were missing. I would request writer to check first script. thanks. kamal.
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
Add Your Feedback!
Note:Not only will your feedback be posted, but an email will be sent to the code's author in your name.

NOTICE: The author of this article has been kind enough to share it with you.  If you have a criticism, please state it politely or it will be deleted.

For feedback not related to this particular article, please click here.
 
Name:
Comment:

 

Categories | Articles and Tutorials | Advanced Search | Recommended Reading | Upload | Newest Code | Code of the Month | Code of the Day | All Time Hall of Fame | Coding Contest | Search for a job | Post a Job | Ask a Pro Discussion Forum | Live Chat | Feedback | Customize | ASP/ VbScript Home | Site Home | Other Sites | About the Site | Feedback | Link to the Site | Awards | Advertising | Privacy

Copyright© 1997 by Exhedra Solutions, Inc. All Rights Reserved.  By using this site you agree to its Terms and Conditions.  Planet Source Code (tm) and the phrase "Dream It. Code It" (tm) are trademarks of Exhedra Solutions, Inc.