logo
g Text Version
Beauty & Self
Books & Music
Career
Computers
Education
Family
Food & Wine
Health & Fitness
Hobbies & Crafts
Home & Garden
Money
News & Politics
Relationships
Religion & Spirituality
Sports
Travel & Culture
TV & Movies

dailyclick
Bored? Games!
Nutrition
Postcards
Take a Quiz
Rate My Photo

new
Action Movies
Bible Basics
Houseplants
Romance Movies
Creativity
Family Travel
Southwest USA


dailyclick
All times in EST

Full Schedule
g
g ASP Site

BellaOnline's ASP Editor

g

Inserting Into a Database with ASP


The INSERT command is very commonly used in ASP to add rows into a SQL database. Here is the syntax for inserting into your tables.

Let's say that you have built yourself a little guestbook, where visitors have a form in which they can enter their name and comments. You now want to insert that name and comments into the table "GUESTBOOK", to store them and show them to your other visitors. Your GUESTBOOK table has 3 fields:

guest_name
guest_comments
guest_date

So your ASP script starts out knowing the value of the name and comments. If you don't know how to get values from a form, read the Using ASP with Forms article. So you now have the variables GuestName and GuestComments filled in with what the user gave you.

Be sure to read about Handling Apostrophes in Input Fields to make sure your input fields are ready for use in SQL.

To do the update, you would use:

Set objCmd4 = Server.CreateObject ("ADODB.Command")
SQLText = "insert into guestbook values('" & GuestName & "', '" & GuestComments & "', '" & Now() & "'"
objCmd4.ActiveConnection = strConnect
objCmd4.CommandType = &H0001
objCmd4.CommandText = SQLText
objCmd4.Execute intRecords
Set objCmd4 = Nothing

This creates the connection, creates the insert statement, submits it, and then shuts down the connection. Note that the Now() command automatically inserts the current date/time, so you know when this user submitted their comment on your site.

Introduction to ASP Ebook

Download this ebook to get everything you need to know about learning ASP - from a step by step tutorial to function lists, sample code, common errors and solutions, and much more! 101 pages.
Add Inserting+Into+a+Database+with+ASP to Twitter Add Inserting+Into+a+Database+with+ASP to Facebook Add Inserting+Into+a+Database+with+ASP to MySpace Add Inserting+Into+a+Database+with+ASP to Del.icio.us Digg Inserting+Into+a+Database+with+ASP Add Inserting+Into+a+Database+with+ASP to Yahoo My Web Add Inserting+Into+a+Database+with+ASP to Google Bookmarks Add Inserting+Into+a+Database+with+ASP to Stumbleupon Add Inserting+Into+a+Database+with+ASP to Reddit




RSS | Related Articles | Editor's Picks Articles | Top Ten Articles | Previous Features | Site Map


For FREE email updates, subscribe to the ASP Newsletter


Past Issues


print
Printer Friendly
bookmark
Bookmark
tell friend
Tell a Friend
forum
Forum
email
Email Editor


Content copyright © 2014 by Lisa Shea. All rights reserved.
This content was written by Lisa Shea. If you wish to use this content in any manner, you need written permission. Contact Lisa Shea for details.

g


g features
Archives | Site Map

forum
Forum
email
Contact

Past Issues
memberscenter


vote
Poetry
Daily
Weekly
Monthly
Less than Monthly



BellaOnline on Facebook
g


| About BellaOnline | Privacy Policy | Advertising | Become an Editor |
Website copyright © 2014 Minerva WebWorks LLC. All rights reserved.


BellaOnline Editor