unable to insert records into access DB
I am trying guestbook.asp given in the ASP3.0 book in chapter 12.
ASP page is able to insert a new record. But when I open the Access
DB file I don't see any data in it other than an new record.
Please help me. I am using WinXP, Access2002.
Guestbook.mdb i downloaded from wrox site.
ASP page is this.
================
<%@ Language=VBScript %>
<html>
<head>
<title>Guest Book Using Connection Object Only</title>
</head>
<body>
<h2>Guest Book Using Connection Object Only</h2>
<%
dbname="guestbook.mdb"
set conn=server.createobject("adodb.connection")
cnpath="DBQ=" & server.mappath(dbname)
'conn.mode = 3
conn.Open "DRIVER={Microsoft Access Driver (*.mdb)}; " & cnpath
'Get the data from the form. We will be inserting it into the database.
'Access doesn't like some characters, such as single-quotes, so encode the
' data using the HTMLEncode method of the ASP Server object.
dim strTB1, strTB2, strTB3, strTB4, strMB1, strCommand
strTB1 = Server.HTMLEncode(Request.QueryString("From"))
strTB2 = Server.HTMLEncode(Request.QueryString("EMailAdd"))
strTB3 = Server.HTMLEncode(Request.QueryString("CC"))
strTB4 = Server.HTMLEncode(Request.QueryString("Subject"))
strMB1 = Server.HTMLEncode(Request.QueryString("Memo"))
'This is a connection string. ADO uses it to connect to a database through the Access driver.
'It needs the provider name of the Access driver and the name of the Access database.
'Connection strings are slightly different, depending on the provider being used,
' but they all use semicolons to separate variables.
'If this line causes and error, search in your registry for
' Microsoft.JET to see if 4.0 is your version.
'strProvider = "Provider=Microsoft.JET.OLEDB.4.0;Data 'Source=C:\InetPub\Wwwroot\Tutorial\guestbook.mdb; "
'This creates an instance of an ADO Connection object.
'There are 4 other ADO objects available to you, each with different methods and
'properties that allow you to do almost anything with database data.
Set objConn = server.createobject("ADODB.Connection")
'The Open method of the Connection object uses the connection string to
' create a connection to the database.
'objConn.Open strProvider
'response.Write strTB1 & & strTB2 & & strTB3 & & strTB4 & & strMB1 & <br>
'Define the query.
'There are many types of queries, allowing you to add, remove, or get data.
'This query will add your data into the database, using the INSERT INTO key words.
'Here, GuestBook is the name of the table.
'You need single-quotes around strings here.
strCommand = "insert into GuestBook (FTB1,FTB2,FTB3,FTB4,FMB1) VALUES ('"
strCommand = strCommand & strTB1 & "','" & strTB2 & "','" & strTB3 & "','" & strTB4 & "','" & strMB1
strCommand = strCommand & "')"
'Execute the query to add the data to the database.
conn.Execute strCommand
Const ForWriting = 2
Const Create = True
Response.Write("Thank you! Your data has been added.")
conn.close
set conn=nothing
%>
</body>
</html>
TIA
Sree
|