asp 中調用存貯過程的一些例子.(1)

來源:互聯網
上載者:User
過程 Return Values how-to Execute a Stored Proc's
This demo It's called ReturnValue.asp and shows you how to execute a stored procedure that has input params, output params, a returned recordset and a return value.

<!-- Author: John Bailey -->


<%@ Language=VBScript %>

<%
'CODE TO CREATE THE STORED PROCEDURE THAT THIS ASP ACCESSES
'Just remove all comments after this line, paste into the SQL query analyzer and run.

'-- insures you use the right database
'use pubs
'GO
'
'-- Creates the procedure
'create procedure sp_PubsTest
'
'-- declare three parameter variables
'  @au_lname varchar (20),  
'  @intID int,
'  @intIDOut int OUTPUT
'
'AS
'
'SELECT @intIDOut = @intID + 1
'
'SELECT *
'FROM authors
'WHERE au_lname LIKE @au_lname + '%'

'RETURN @intID + 2

%>



<%

'THIS IS THE ASP CODE. Just run from the server.

Option Explicit

Dim CmdSP
Dim adoRS
Dim adCmdSPStoredProc
Dim adParamReturnValue
Dim adParaminput
Dim adParamOutput
Dim adInteger
Dim iVal
Dim oVal
Dim adoField
Dim adVarChar

adCmdSPStoredProc = 4
adParamReturnValue = 4
adParaminput = 1
adParamOutput = 2
adInteger = 3
adVarChar = 200

iVal = 5
oVal = 3


  '-- Create a command object --
  set CmdSP = Server.CreateObject("ADODB.Command")

  '-- Make an ODBC connection to the (local) SQL server,
  '-- connecting to the Pubs database with the default sa login and empty password
  CmdSP.ActiveConnection = "Driver={SQL Server};server=(local);Uid=sa;Pwd=;Database=Pubs"
  

  '-- define the name of the command  
  CmdSP.CommandText = "sp_PubsTest"
  
  
  '-- define the type of the command as a stored procedure (numeric value = 4)
  CmdSP.CommandType = adCmdSPStoredProc
  
  
  '-- define the first parameter - the one the procedure will return
  '-- the calls are:
  '--   CmdSP.Parameters.Append: append this parameter to the collection for this command object
  '--   CmdSP.CreateParameter(): creates the parameter using the values given:
  '--      "RETURN_VALUE" is the name of the parameter for later reference
  '--      adInteger (value = 3) indicates this parameter is an integer datatype
  '--      adParamReturnValue (value = 4) indicates this parameter is expected to be returned
  '--      4 is an arbitrary initial value for this parameter

  CmdSP.Parameters.Append CmdSP.CreateParameter("RETURN_VALUE", adInteger, adParamReturnValue, 4)


  '-- define the first parameter - the one the procedure will return
  '-- the calls are:
  '--   CmdSP.Parameters.Append: append this parameter to the collection for this command object
  '--   CmdSP.CreateParameter(): creates the parameter using the values given:
  '--      "@au_lname" is the name of the parameter for later reference
  '--      adVarChar (value = 200) indicates this parameter is a string datatype
  '--      adParamInput (value = 1) indicates this parameter is for input
  '--      20 is the size of the string in characters
  '--      "M" is an arbitrary initial value for this parameter
  
  CmdSP.Parameters.Append CmdSP.CreateParameter("@au_lname", adVarChar, adParaminput, 20, "M")


  '-- define the first parameter - the one the procedure will return
  '-- the calls are:
  '--   CmdSP.Parameters.Append: append this parameter to the collection for this command object
  '--   CmdSP.CreateParameter(): creates the parameter using the valu



相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.