'Recordset in asp and execute stored procedure in asp
I want to open another .asp page from one .asp page on button click following is the code i have done but error is coming
Error is coming as "operation is not allowed when the object is closed"
Here is the code
Dim dbconn, objCmd, objParam, rs, EmailID, Password, connString, RecordCount
connString = "Connectionstring"
dbconn = Server.CreateObject("ADODB.Connection")
dbconn.Open(connString)
rs = Server.CreateObject("ADODB.RecordSet")
objCmd = Server.CreateObject("ADODB.Command")
objCmd.ActiveConnection = dbconn
objCmd.CommandText = "sp_Name"
objCmd.CommandType = &H0004
objParam = objCmd.CreateParameter("@EmailID",200,1,"100",Session("EmailID"))
objCmd.Parameters.Append(objParam)
objParam = objCmd.CreateParameter("@Password",200,1,"100",Session("Password"))
objCmd.Parameters.Append(objParam)
rs = objCmd.Execute(Session("EmailID"),Session("Password"))
do while not rs.eof ------->here comes error
EmailID = rs(0)
Password = rs(1)
'response.Write EmailID & "," & Password & "<br">
rs.MoveNext
loop
Solution 1:[1]
try with below code.
SET rs = objCmd.Execute(Session("EmailID"),Session("Password"))
Add SET before rs
Solution 2:[2]
Here is my suggestion.
In my case, RecordSet object from Command.Execute() does not support .BOF nor EOF.
So, I use RecordSet.Open method to call a stored procedure like this....
Dim dbconn, objCmd, objParam, rs, EmailID, Password, connString, RecordCount
connString = "Connectionstring"
dbconn = Server.CreateObject("ADODB.Connection")
dbconn.Open(connString)
rs = Server.CreateObject("ADODB.RecordSet")
objCmd = Server.CreateObject("ADODB.Command")
objCmd.ActiveConnection = dbconn
objCmd.CommandText = "sp_Name"
objCmd.CommandType = &H0004
objParam = objCmd.CreateParameter("@EmailID",200,1,"100",Session("EmailID"))
objCmd.Parameters.Append(objParam)
objParam = objCmd.CreateParameter("@Password",200,1,"100",Session("Password"))
objCmd.Parameters.Append(objParam)
rs.Open objCmd, dbconn, 1, 1
do while not rs.eof ------->here comes error
EmailID = rs(0)
Password = rs(1)
'response.Write EmailID & "," & Password & "<br">
rs.MoveNext
loop
I hope it's not too late!!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Jinesh Jain |
| Solution 2 | Kwangsoo |
