Username: Password:

ASP中怎样执行存储过程?
来源:作者: 发布时间:2007-11-09 05:14:02

1. 什么是存储过程?

存储过程是SQL server所提供的Tranact-SQL语言所编写的程式。

2. 怎样建立存储过程?

Create Procedure EmployeeID_Orders

@EmployeeID as int

as

select * from orders

where employeeID=@EmployeeID

3. ASP中执行存储过程:

A. 编写sql语句:“execute 存储过程名 参数”,再通过connection.execute或recordset.open执行

strSql="execute employeeID_Orders 1"

Set objRstOrders=objCnnNorthwind.Execute(strSql)

B. 通command对象执行类型为acCmdStoredProc的命令

‘建立Command对象

Set objCmdNorthwind=Server.CreateObject("ADODB.Command")

‘设定命令的文本

objCmdNorthwind.CommandText="EmployeeID_Orders"

‘设定命令的类型

objCmdNorthwind.CommandType=adCmdStoredProc

‘设定命令对象使用的连接对象

Set objCmdNorthwind.ActiveConnection=objCnnNorthwind



‘建立参数对象

Set objParam=objCmdNorthwind.CreateParameter("@EmployeeID",adInteger,adParamInput)

‘把参数对象添加到命令对象的参数集中

objCmdNorthwind.Parameters.Append objParam

‘设定参数的值

objParam.Value=2



‘执行命令对象

Set objRstOrders=objCmdNorthwind.Execute()

‘销毁命令对象

Set objCmdNorthwind=Nothing


喜欢本文,那就收藏到:

    Del.icio.us Google书签 Digg Live Bookmark Technorati Furl Yahoo书签 Facebook 百度搜藏 新浪ViVi 365Key网摘 天极网摘 和讯网摘 博拉网 POCO网摘 添加到饭否 QQ书签 Digbuzz我挖网
相关评论  我也要评论
还没有关于此文章的相关评论!
  • 昵称: (为空则显示guest)
  • 评论分数: ★ ★ ★★★ ★★★★ ★★★★★
  • 评论内容:(不能超过250字,需审核后才会公布,请自觉遵守互联网相关政策法规。
  • 导航
    赞助商
    文章类别
    订阅