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.
Create a Table named ''messages''. Use the following data field settings.
| Field Name | Data Type | Field Size |
| id | AutoNumber | |
| name | Text | 50 |
| 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.
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.
A.B.N: 96 996 282 647


