ASP中如何執行存儲過程?

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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章