Web Development

  Homes arrow Web Development arrow Inserting data into a Database table using AS...
 Webmaster Tools
Base64 Encoding 
Browser Settings 
CSS Coder 
CSS Navigation Menu 
Datetime Converter 
DHTML Tooltip 
Dig Utility 
DNS Utility 
Dropdown Menu 
Fetch Content 
Fetch Header 
Floating Layer 
htaccess Generator 
HTML Encoder 
HTML Entities 
IP Convert 
Meta Tags 
Password Encryption
Password Strength
Pattern Extractor 
Ping Utility 
Pop-Up Window 
Regex Extractor 
Regex Match 
Scrollbar Color 
Source Viewer 
Syntax Highlighting 
URL Encoding 
Web Safe Colors 
Forums Sitemap 
Weekly Newsletter
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Contact Us 
Site Map 
Privacy Policy 
  >>> SIGN UP!  
  Lost Password? 

Inserting data into a Database table using ASP
By: Developer Shed
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 15

    Table of Contents:

    Rate this Article: Poor Best 
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article




    by: Codefixer.com

    Inserting data into a Database table using ASP

    The code below simply inserts data into the table called 'tblFriends' in an Access database called 'Friends.mdb'. The table has 3 columns, firstly an 'Id' field that is an autonumber, secondlya field called 'FirstName' which is a textfield and lastly another textfieldcalled 'SurName'.

    We will use a DSN-less connection in this example.
    Below is the code for our file 'insert.asp'

    <% @ Language="VBScript" %>
    <% Option Explicit

    'declare your variables
    dim connection
    dim sSQL,sConnString

    'declare SQL statement that will query the database
    sSQL="INSERT INTO tblFriends (FirstName, SurName) VALUES ('Michael', 'Wall')"

    'define the connection string, specify database
    ' driver and the location of database

    sConnString="DRIVER={Microsoft Access Driver (*.mdb)};" & _
    "DBQ=" & Server.MapPath("Friends.mdb") & ";"

    'create an ADO connection object
    Set connection = Server.CreateObject("ADODB.Connection")

    'Open the connection to the database


    'execute the SQL

    'check to see if there were any errors
    If err.number=0 Then
    response.write "the data was inserted successfully."
    End If

    'close the object and free up resources

    Set Connection = Nothing

    Remember that if you are using this script keep the page and the database in the same folder otherwise you will have to change the path to the database.
    Note that the value of Id in your database table will automatically increase each time you run this script hence the name 'autonumber'. The value of ID will also be unique.
    Also note that we haven't used the the recordset object as we are not returninga recordset, we are simply inserting data not retrieving data.

    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

    More Web Development Articles
    More By Developer Shed



    - On Page SEO for New Domains
    - Improve Your Site`s Speed
    - Safari Books Online Review
    - Creating an Estore From the Ground Up
    - Most Common SEO Mistakes Developers Make
    - Making the Most of Your Titles and Meta Desc...
    - Five Ways Using Flash Can Damage Your Site
    - A Web Designer`s Guide to Colors
    - Use Webstarts to Create a Free Site
    - More Than Just Looks. How Your Web Design C...
    - How to Design Content Pages
    - Mint Review
    - Make Your WordPress Website Look Professional
    - How to Create a Mobile Web Site
    - Meta Tags: Still Useful?

    Developer Shed Affiliates


    © 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap