|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Hi,
I'm getting the error "Operation is not allowed when the object is closed" from the code at the end of this message. The really funny thing is that the operation in question is objRSInsert.close, and I'm pretty sure I haven't already closed it. Any ideas? Thanks, Sara Const adOpenDynamic = 2 Const adLockBatchOptimistic = 4 Const adCmdText = &H0001 Dim objConn, objRSInsert, strSQLInsert, strAuthorname, strAuthorid, strAuthaffil, strAuthoremail strAuthorname = Request.QueryString("authorname") strAuthorid = Request.QueryString("authorid") strAuthaffil = Request.QueryString("authaffil") strAuthoremail = Request.QueryString("authemail") Set objConn = Server.CreateObject("ADODB.Connection") objConn.Open strConnect Set objRSInsert = Server.CreateObject("ADODB.Recordset") strSQLInsert = "INSERT INTO tblAuthor (author_id, author_name, author_affiliation, author_email) " strSQLInsert = strSQLInsert & "VALUES (" & "'" & strAuthorid & "', " & "'" & strAuthorname & "', " strSQLInsert = strSQLInsert & "'" & strAuthaffil & "', " & "'" & strAuthoremail & "')" objRSInsert.Open strSQLInsert, objConn, adOpenDynamic, adLockBatchOptimistic, adCmdText Response.Write "The author has been added to the database.<br />" Response.Write strAuthorid & " " & strAuthorname & ", " & strAuthaffil & ", " & strAuthoremail objRSInsert.Close Set objRSInsert = Nothing objConn.Close Set objConn = Nothing |
|
#2
|
||||
|
||||
|
I'm not familiar with this error but I searched Operation is not allowed when the object is closed in Google and found some pages. Here's one from the Microsoft website. You might want to do a search for this error on Google because I see a lot of resources.
__________________
Keep it Prodigy, Keep it Real |
|
#3
|
||||
|
||||
|
Use the following for your code:
Code:
Dim objConn, objRSInsert, strSQLInsert, strAuthorname, strAuthorid, strAuthaffil, strAuthoremail
strAuthorname = Request.QueryString("authorname")
strAuthorid = Request.QueryString("authorid")
strAuthaffil = Request.QueryString("authaffil")
strAuthoremail = Request.QueryString("authemail")
Set objConn = Server.CreateObject("ADODB.Connection")
DBPath = Server.MapPath( "YourDbName.mdb" )
'open the db with the driver you're using
'you may change it to match your needs, if it's not this one reply back
objConn.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & DBPath
'build the SQL statement
strSQLInsert = "INSERT INTO tblAuthor (author_id, author_name, author_affiliation, author_email) "
strSQLInsert = strSQLInsert & "VALUES (" & "'" & strAuthorid & "', " & "'" & strAuthorname & "', "
strSQLInsert = strSQLInsert & "'" & strAuthaffil & "', " & "'" & strAuthoremail & "')"
objConn.Execute(strSQLInsert)
'write proper message for the user
Response.Write "The author has been added to the database.<br />"
Response.Write strAuthorid & " " & strAuthorname & ", " & strAuthaffil & ", " & strAuthoremail
'reclaim system resources
objConn.Close
Set objConn = Nothing
Not sure why you're trying to use the code thru a recordset. Recordsets should only be used when you need to go thru db records. For insertion the above code should work.
__________________
................... ASCII and ye shall receive .................. Knowledge is the only resource on earth that multiplies when shared Support the Shemzilla Project Powered by C# |
|
#4
|
||||
|
||||
|
As lewy showed you can accomplish this very easily.
Example: Code:
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open strConnect
strSQLInsert = "INSERT INTO tblAuthor (author_id, author_name, author_affiliation, author_email) "
strSQLInsert = strSQLInsert & "VALUES (" & "'" & strAuthorid & "', " & "'" & strAuthorname & "', "
strSQLInsert = strSQLInsert & "'" & strAuthaffil & "', " & "'" & strAuthoremail & "')"
Conn.Execute(strSQLInsert)
Conn.Close
Set Conn = Nothing
|
|
#5
|
|||
|
|||
|
I'm a newbie, so your help is greatly appreciated!
Quote:
|
![]() |
| Viewing: ASP Free Forums > Other > Programming Help > "Operation is not allowed when the object is closed" error |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|