asp中的记录集并在asp中执行存储过程?

内容来源于 Stack Overflow,并遵循CC BY-SA 3.0许可协议进行翻译与使用

  • 回答 (2)
  • 关注 (0)
  • 查看 (80)

我想在按钮单击下从一个.asp页面打开另一个.asp页面以下是我已完成的代码,但错误即将来临

错误即将发生,因为“ 当对象关闭时不允许操作

这是代码

 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
提问于
用户回答回答于

试试下面的代码。

SET rs = objCmd.Execute(Session("EmailID"),Session("Password"))

在rs之前添加SET

用户回答回答于

在我的例子中,Command.Execute()的RecordSet对象不支持.BOF和EOF。

所以,我使用RecordSet.Open方法来调用这样的存储过程....

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

扫码关注云+社区

领取腾讯云代金券