- 作者:zhaozj
- 发表时间:2020-12-23 10:53
- 来源:未知
<% '建立对象 set oConn = Server.CreateObject("ADODB.Connection") set oRs = Server.CreateObject("ADODB.Recordset") set oCmd = Server.CreateObject("ADODB.Command") '数据连接 strConn = "DRIVER={SQL Server};Server=web;UID=sa;PWD=123;DataBase=stefli_gb" oConn.open strConn '创建存储过程 'strPro = "CREATE PROC selectname(@id int,@name varchar out) AS SELECT name FROM userdata WHERE id=@id" 'oConn.Execute strPro '传递参数 oCmd.CommandText = "selectname" oCmd.CommandType = 4 oCmd.Parameters.Append oCmd.CreateParameter("@id",3,1) oCmd.Parameters("@id") = Request.Form("id") oCmd.Parameters.Append oCmd.Createparameter("@name",4,2) oCmd.ActiveConnection = oConn Set oRs = oCmd.Execute() '结果输出 Response.Write "<b>结果是:" & oRs("name") & "</b>" %> 不过有点问题,就是那个("@name",4,2)里面的4,按理应该是200,不知道为什么200就是不行,就4行,有知道请说明一下~ 以下是表结构和运行结果: DataBase:stefli_gb Table :userdata 字段名 类型 大小 id int 4(标识) name Varchar 50 Data: id name 1 stefli 2 joy 3 haha 4 test Procedure: CREATE PROC selectname(@id int,@name Varchar output) AS SELECT name FROM userdata WHERE id=@id GO 结果是:stefli