|
OK, so I see that there are quite a few people here that have the same error as I, but I can't seem to see where the error starts or ends, or whatever...
Anyway, I get this specific error:
Error Type:
ADODB.Recordset (0x800A0E78)
Operation is not allowed when the object is closed.
/add_backup.asp, line 39
Line 39 is this: rsAddMovie.AddNew
I wish I new where are good debugger was for ASP and SQL like Visual Basic, where I could insert a break point and SEE the error occur with my own eyes, and therefore know what to fix.
Anyway, below is the ASP code from the HTML form then after, redirect to a page that shows all the data I wish to see in the MS Access Database, which is only 2 records (manually inserted).
Don't comment on the missing delimiters, I took them out for this Thread.
HELP!!!!
///////////////ASP Code to process from HTML Form///////////////
'Dimension variables
Dim conn 'Holds the Database Connection Object
Dim rsAddMovie 'Holds the recordset for the new record to be added
Dim strSQL 'Holds the SQL query to query the database
'Create an ADO connection object
Set conn = Server.CreateObject("ADODB.Connection")
'Set an active connection to the Connection object using a DSN-less connection
conn.Open "DSN=movie"
'Create an ADO recordset object
Set rsAddMovie = Server.CreateObject("ADODB.Recordset")
'Initialise the strSQL variable with an SQL statement to query the database
strSQL = "INSERT INTO tblMovies (MovieName, GenreID, Director, YearReleased, Length, RatingID, Review, CodecID, CDs, Notes) VALUES ('" & request.form("txtMovieName") & "'," & request.form("optGenre") & ",'" & request.form("txtDirector") & "','" & request.form("txtYearReleased") & "','" & request.form("txtLength") & "'," & request.form("optRating") & ",'" & request.form("txtReview") & "'," & request.form("optCodec") & ",'" & request.form("txtCds") & "','" & request.form("txtNotes") & "')"
strSQL = "INSERT INTO tblActors (Fname, Lname) VALUES ('" & request.form("txtFname") & "','" & request.form("txtLname") & "')"
conn.Execute (strSQL)
'Set the cursor type we are using so we can navigate through the recordset
rsAddMovie.CursorType = 2
'Set the lock type so that the record is locked by ADO when it is updated
rsAddMovie.LockType = 3
'Open the recordset with the SQL query
rsAddMovie.Open strSQL, conn
'Tell the recordset we are adding a new record to it
rsAddMovie.AddNew
'Add a new record to the recordset
rsAddMovie.Fields("MovieName") = Request.Form("txtMovieName")
rsAddMovie.Fields("GenreID") = Request.Form("optGenre")
rsAddMovie.Fields("Director") = Request.Form("txtDirector")
rsAddMovie.Fields("YearReleased") = Request.Form("txtYearReleased")
rsAddMovie.Fields("Length") = Request.Form("txtLength")
rsAddMovie.Fields("RatingID") = Request.Form("optRating")
rsAddMovie.Fields("Review") = Request.Form("txtReview")
rsAddMovie.Fields("CodecID") = Request.Form("optCodec")
rsAddMovie.Fields("CDs") = Request.Form("txtCds")
rsAddMovie.Fields("Notes") = Request.Form("txtNotes")
rsAddMovie.Fields("Fname") = Request.Form("txtFname")
rsAddMovie.Fields("Lname") = Request.Form("txtLname")
'Write the updated recordset to the database
rsAddMovie.Update
'Reset server objects
rsAddMovie.Close
Set rsAddMovie = Nothing
Set conn = Nothing
'Redirect to the movie.asp page
Response.Redirect "http://localhost/movie.asp"
An easy, understandable, Down to Earth explanation and fix would be greatly appreciated. Thanks!!
|
|
|
instead of this
conn.Execute (strSQL)
try
set rsAddMovie = conn.Execute (strSQL)
Also your first value assignment in strSQL did not actually do anything at all since your next line immediately overwrites the value stored in strSQL
|
|
|
|
|
|
|
// |