Economical Australian Domain Names
Home » Articles » ASP Tutorials » Adding Data to an Access Database in ASP by using Sql INSERT INTO Statement
Adding Data to an Access Database in ASP by using Sql INSERT INTO Statement

We can add data to an Access Database from our ASP pages. In this turorial, I will show you how to add data to an Access database by using SQL INSERT INTO Statement.

First we need to create an Access Database. Open Microsoft Access Program and crate a database and name it as ''guest.mdb''. If you don''t have Microsoft Access Program then, download the Database here.

 

Crate Database (guest.mdb)

 

Create a Table named ''messages''. Use the following data field settings.

 

Field Name Data Type Field Size
id AutoNumber  
name Text 50
email Text 50
message Text 255
sign_date Date/Time  

 

We have created a Tables containing ''id'', ''name'', ''email'', ''message'', ''sign_date'' fields. In this Table, we have added ''id'' field and set its data type to ''AutoNumber''. This field will store an integer number and will get increments automatically whenever a new record is added. So that we can identify a record by seeing this ''id'' number field.

 

Adding Data to Database

After creating database, we will write ASP code to connect to database and add data to the database. Please examine the code below how to add data to Access database by using SQL INSERT INTO Statement.

 

"add_data.asp"

<%

'declare variables

Dim conn, strSQL, strName, strEmail, strMessage, Sign_Date

'Set values into variables

strName = "DigitalArakakn.Net"

strEmail = "contact@digitalarakan.net"

strMessage = "Adding data to an Access Database in ASP."

Sign_Date = Date()

'create connection object

Set conn = Server.CreateObject("ADODB.Connection")

'open dababase

conn.Open "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("guest.mdb")

'create SQL string for inserting data into database

strSQL = "INSERT INTO messages (name, email, message, sign_date) VALUES ('"& strName &"','"& strEmail &"','"& strMessage &"','"& Sign_Date &"')"

'now add data with Execute() method

conn.Execute(strSql)

'close connection object

conn.Close

Set conn = Nothing

%>

 

Download the Tutorial HERE.

This is a one-stop website that meets all your online business needs.This website offer domain registration, web hosting, email hosting, secure ssl certificate, internet software products and development services.
©2004-2009 EcoWeb4u Web Solutions | Queensland, Australia. All trademarks are the property of their respective owners.
A.B.N: 96 996 282 647