ASP 3.0 - Problems Inserting into Database w/ SQL
I'm currently following my Wrox Beginning ASP 3.0 book, and I'm upto the bit on inserting data INTO databases. I have an example from the book (chapter 14, page 603) that WILL NOT work, here's the code:
<%
Option Explicit
Dim strConnect
%>
<!-- metadata type = "typelib"
file = "C:\Program Files\Common Files\System\ado\msado15.dll" -->
<html>
<head>
<title>ADO Command Object</title>
</head>
<body>
<%
Dim objRS, objComm, intNoOfRecords
Set objComm = Server.CreateObject("ADODB.Command")
objComm.ActiveConnection = strConnect
objComm.CommandText = "INSERT INTO Movies(MovieID, Title) VALUES (333, 'Psycho')"
objComm.CommandType = adCmdText
objComm.Execute intNoOfRecords
Response.Write "The INSERT command has been executed; Number of records inserted = " & intNoOfRecords & ""
objComm.CommandText = "SELECT * FROM Movies WHERE Title LIKE 'Psycho'"
Set objRS = objComm.Execute
Response.Write "The SELECT command has been executed, " & _
"and has selected the following records: <br>"
While Not objRS.EOF
Response.Write "MovieID = " & objRS("MovieID") & _
"; Title = " & objRS("Title") & "<br>"
objRS.MoveNext
Wend
objRS.Close
Set objRS = Nothing
objComm.CommandText = "DELETE FROM Movies WHERE Title LIKE 'Psycho'"
objComm.Execute intNoOfRecords
Response.Write "The DELETE command has been executed, " & _
"Number of records deleted = " & intNoOfRecords & "<br>"
Set objComm = Nothing
%>
</body>
</html>
All the syntax should be correct as it's taken directly from the Wrox website. It says "Page Cannot be displayed" and I get the following error message:
Error Type:
Microsoft JET Database Engine (0x80004005)
Operation must use an updateable query.
/asp_test/SQLInsertDelete.asp, line 20
What could be wrong? I can retrieve data from the database just fine using SQL SELECT statements, just when I try to change data it won't let me. Please please help!!
Thank you!
Sunday Ironfoot
|