01.
<%
Option
Explicit %>
02.
<html>
03.
<head>
04.
<title>ThaiCreate.Com ASP & Microsoft Access Tutorial</title>
05.
</head>
06.
<body>
07.
<%
08.
Dim
Conn,strSQL,objRec,objExec
09.
Set
Conn = Server.Createobject(
"ADODB.Connection"
)
10.
Conn.Open
"DRIVER=Microsoft Access Driver (*.mdb);DBQ="
& Server.MapPath(
"mydatabase.mdb"
),
""
,
""
11.
strSQL =
"SELECT * FROM customer WHERE CustomerID = '"
&Request.Form(
"txtCustomerID"
)&
"' "
12.
Set
objRec = Conn.Execute(strSQL)
13.
IF
Not
objRec.EOF
Then
14.
Response.write(
"CustomerID already exist."
)
15.
Else
16.
strSQL =
""
17.
strSQL = strSQL &
"INSERT INTO customer "
18.
strSQL = strSQL &
"(CustomerID,Name,Email,CountryCode,Budget,Used) "
19.
strSQL = strSQL &
"VALUES "
20.
strSQL = strSQL &
"('"
&Request.Form(
"txtCustomerID"
)&
"','"
&Request.Form(
"txtName"
)&
"', '"
&Request.Form(
"txtEmail"
)&
"' "
21.
strSQL = strSQL &
",'"
&Request.Form(
"txtCountryCode"
)&
"','"
&Request.Form(
"txtBudget"
)&
"', '"
&Request.Form(
"txtUsed"
)&
"') "
22.
Set
objExec = Conn.Execute(strSQL)
23.
If
Err.Number = 0
Then
24.
Response.write(
"Save Done."
)
25.
Else
26.
Response.write(
"Error Save ["
&strSQL&
"] ("
&Err.Description&
")"
)
27.
End
If
28.
29.
Set
objExec =
Nothing
30.
31.
End
If
32.
objRec.Close
33.
Conn.Close()
34.
Set
objRec =
Nothing
35.
Set
Conn =
Nothing
36.
%>
37.
</body>
38.
</html>