Wednesday, April 11, 2012

Return SCOPE_IDENTITY() without using CreateParam

I'm trying this but getting an error ADODB.Recordset error '800a0e78' Operation is not allowed when the object is closed. on the line with this code If ScopeID.EOF Then



Please do not answer to use the CreateParam method, Looking for a solution without this method. Thanks.



<%  
set Cmd = Server.CreateObject("ADODB.Command")
Cmd.ActiveConnection = conn

Cmd.CommandText = "INSERT INTO TABLE (NAME) VALUES ('test') SELECT SCOPE_IDENTITY() AS ID"
Cmd.CommandType = 1
Cmd.CommandTimeout = 0
Cmd.Prepared = true

Set ScopeID = Cmd.Execute()

If ScopeID.EOF Then
Response.Write "There was an Error in your request, Please try again"
Response.End
Else
ID= ScopeID(0).Value
End IF

ScopeID.Close
Set ScopeID = Nothing
Set Cmd = Nothing

Response.Write ID

%>




No comments:

Post a Comment