小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

如何從 ASP 調(diào)用 SQL Server 存儲(chǔ)過(guò)程

 liu_jinbo 2006-08-25

如何從 ASP 調(diào)用 SQL Server 存儲(chǔ)過(guò)程

概要

null
有關(guān)本文的 Microsoft Visual Basic .NET 版本,請(qǐng)參閱 306574 (http://support.microsoft.com/kb/306574/)
本文演示了使用 ActiveX 數(shù)據(jù)對(duì)象 (ADO) 從 Active Server Pages 調(diào)用存儲(chǔ)過(guò)程的三種方法。

更多信息

null
下面的示例使用 Command 對(duì)象調(diào)用示例存儲(chǔ)過(guò)程 sp_test。此存儲(chǔ)過(guò)程接受整數(shù),同時(shí)返回一個(gè)整數(shù)值:


<%@ LANGUAGE="VBSCRIPT" %> <!--#include virtual="/ASPSAMP/SAMPLES/ADOVBS.INC"--> <HTML> <HEAD><TITLE>Place Document Title Here</TITLE></HEAD> <BODY> This first method queries the data source about the parameters of the stored procedure. This is the least efficient method of calling a stored procedure.<BR> <% Set cn = Server.CreateObject("ADODB.Connection") Set cmd = Server.CreateObject("ADODB.Command") cn.Open "data source name", "userid", "password" Set cmd.ActiveConnection = cn cmd.CommandText = "sp_test" cmd.CommandType = adCmdStoredProc ‘ Ask the server about the parameters for the stored proc cmd.Parameters.Refresh ‘ Assign a value to the 2nd parameter. ‘ Index of 0 represents first parameter. cmd.Parameters(1) = 11 cmd.Execute %> Calling via method 1<BR> ReturnValue = <% Response.Write cmd.Parameters(0) %><P> <!-- ************************************************************ --> Method 2 declares the stored procedure, and then explicitly declares the parameters.<BR> <% Set cn = Server.CreateObject("ADODB.Connection") cn.Open "data source name", "userid", "password" Set cmd = Server.CreateObject("ADODB.Command") Set cmd.ActiveConnection = cn cmd.CommandText = "sp_test" cmd.CommandType = adCmdStoredProc cmd.Parameters.Append cmd.CreateParameter("RetVal", adInteger, _ adParamReturnValue) cmd.Parameters.Append cmd.CreateParameter("Param1", adInteger, _ adParamInput) ‘ Set value of Param1 of the default collection to 22 cmd("Param1") = 22 cmd.Execute %> Calling via method 2<BR> ReturnValue = <% Response.Write cmd(0) %><P> <!-- ************************************************************ --> Method 3 is probably the most formal way of calling a stored procedure. It uses the canocial <% Set cn = Server.CreateObject("ADODB.Connection") cn.Open "data source name", "userid", "password" Set cmd = Server.CreateObject("ADODB.Command") Set cmd.ActiveConnection = cn ‘ Define the stored procedure‘s inputs and outputs ‘ Question marks act as placeholders for each parameter for the ‘ stored procedure cmd.CommandText = "{?=call sp_test(?)}" ‘ specify parameter info 1 by 1 in the order of the question marks ‘ specified when we defined the stored procedure cmd.Parameters.Append cmd.CreateParameter("RetVal", adInteger, _ adParamReturnValue) cmd.Parameters.Append cmd.CreateParameter("Param1", adInteger, _ adParamInput) cmd.Parameters("Param1") = 33 cmd.Execute %> Calling via method 3<BR> ReturnValue = <% Response.Write cmd("RetVal") %><P> </BODY> </HTML>
請(qǐng)注意,上面的示例使用了訪問(wèn) Command 對(duì)象的 Parameters 集合的各種方法。有些方法使用 Command 對(duì)象的默認(rèn)集合,
而其他方法指定了要訪問(wèn)的特定集合的屬性。



這篇文章中的信息適用于:
Microsoft Active Server Pages 4.0
Microsoft ActiveX Data Objects 2.0
Microsoft ActiveX Data Objects 2.7
Microsoft ActiveX Data Objects 2.7
Microsoft ActiveX Data Objects 2.5
Microsoft ActiveX Data Objects 2.6
Microsoft ActiveX Data Objects 2.7

    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購(gòu)買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶 評(píng)論公約

    類似文章 更多