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
European Travel
Action Movies
Bible Basics
Houseplants
Romance Movies
Creativity
Family Travel


dailyclick
All times in EST

Autism Spectrum Disorders: 4:00 PM

Full Schedule
g
g ASP Site

BellaOnline's ASP Editor

g

Updating a SQL Database with ASP


Often, you'll want to use ASP to update a database record using SQL. Here is how it is done!

Let's say you are writing ad rotation code, and you have already done the Select of the Ad. Now you want to update the database row so that the ad's "view counter" is incremented by one. That is, if that particular ad, say for google.com, had previously been shown 99 times, you now want it to say that it has been shown 100 times.

So, after you run that previous code to get the ADID and ADCODE, you would display the ad code on the screen however you choose to use it. And then it's time to increment. You would use:

Set objCmd4 = Server.CreateObject ("ADODB.Command")
SQLText = "update ads set hit_count = hit_count + 1 where ad_id = " & AdID
objCmd4.ActiveConnection = strConnect
objCmd4.CommandType = &H0001
objCmd4.CommandText = SQLText
objCmd4.Execute intRecords
Set objCmd4 = Nothing

This creates the connection, writes the update statement, submits it, and then shuts down the connection. You can use this to do any sort of command to the database - from inserting records, deleting records, updating existing records, and more!

If you're using character/string values, be sure to read about Handling Apostrophes in Input Fields to make sure your input fields are ready for use in SQL.

Advanced SQL Update Command: Using Two Tables

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 Updating+a+SQL+Database+with+ASP to Twitter Add Updating+a+SQL+Database+with+ASP to Facebook Add Updating+a+SQL+Database+with+ASP to MySpace Add Updating+a+SQL+Database+with+ASP to Del.icio.us Digg Updating+a+SQL+Database+with+ASP Add Updating+a+SQL+Database+with+ASP to Yahoo My Web Add Updating+a+SQL+Database+with+ASP to Google Bookmarks Add Updating+a+SQL+Database+with+ASP to Stumbleupon Add Updating+a+SQL+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