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

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

new
Sewing
Jewelry Making
ABC Soaps
Fragrance
Movie Mistakes
Honeymoon
MP3 / iTunes


dailyclick
All times in EST

Autism Spectrum Disorders: 4:00 PM

Full Schedule
g
g ASP Site
Editor Wanted
BellaOnline's ASP Editor

g

Inserting Into a Database with ASP
Guest Author - Lisa Shea

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.

This site needs an editor - click to learn more!

RSS | Related Articles | Previous Features | Site Map


Content copyright © 2009 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 BellaOnline Administration for details.

Digg! g delicious Save to Del.icio.us

g


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

g features
Best uses for RSS

RSS and its future.

Force Download Dialog box with ASP

Archives | Site Map

forum
Forum
email
Contact

Past Issues
memberscenter


vote
Growing a Garden
Veggies and Flowers
Veggies Only
Flowers Only
No Garden

g


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


BellaOnline Editor