| /*SP1*/ CREATE PROCEDURE dbo.getUserList as set nocount on begin select * from dbo.[userinfo] end go |
| '**通过Command对象调用存储过程** DIM MyComm,MyRst Set MyComm = Server.CreateObject("ADODB.Command") MyComm.ActiveConnection = MyConStr 'MyConStr是数据库连接字串 MyComm.CommandText = "getUserList" '指定存储过程名 MyComm.CommandType = 4 '表明这是一个存储过程 MyComm.Prepared = true '要求将SQL命令先行编译 Set MyRst = MyComm.Execute Set MyComm = Nothing |
| '**通过Connection对象调用存储过程** DIM MyConn,MyRst Set MyConn = Server.CreateObject("ADODB.Connection") MyConn.open MyConStr 'MyConStr是数据库连接字串 Set MyRst = MyConn.Execute("getUserList",0,4) '最后一个参断含义同CommandType Set MyConn = Nothing '**通过Recordset对象调用存储过程** DIM MyRst Set MyRst = Server.CreateObject("ADODB.Recordset") MyRst.open "getUserList",MyConStr,0,1,4 'MyConStr是数据库连接字串,最后一个参断含义与CommandType相同 |
| /*SP2*/ CREATE PROCEDURE dbo.delUserAll as set nocount on begin delete from dbo.[userinfo] end go |
| '**通过Command对象调用存储过程** DIM MyComm Set MyComm = Server.CreateObject("ADODB.Command") MyComm.ActiveConnection = MyConStr 'MyConStr是数据库连接字串 MyComm.CommandText = "delUserAll" '指定存储过程名 MyComm.CommandType = 4 '表明这是一个存储过程 MyComm.Prepared = true '要求将SQL命令先行编译 MyComm.Execute '此处不必再取得记录集 Set MyComm = Nothing |
当然也可通过Connection对象或Recordset对象调用此类存储过程,不过建立Recordset对象是为了取得记录集,在没有返回记录集的情况下,还是利用Command对象吧。