Some examples of the storage process being invoked in ASP. (1)

Source: Internet
Author: User
Tags numeric value odbc connection reference
Procedure return Values How-to Execute a Stored Proc ' s
This demo It's called Returnvalue.asp and shows to execute a stored procedure the has input params, output params , a returned recordset and a return value.

<!--Author:john Bailey-->


<%@ Language=vbscript%>

<%
' CODE to CREATE ' The STORED PROCEDURE so this ASP accesses
' Just Remove all comments on this line, paste into the SQL Query Analyzer and run.

'--Insures 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 a 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=;D Atabase=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 Parameter-the one, the procedure would 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 was an integer datatype
'--adparamreturnvalue (value = 4) indicates this parameter was expected to be returned
'-4 is a arbitrary initial value for this parameter

CmdSP.Parameters.Append cmdsp.createparameter ("Return_value", Adinteger, adParamReturnValue, 4)


'--Define the Parameter-the one, the procedure would 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 =) indicates this parameter is a string datatype
'--adparaminput (value = 1) indicates this parameter was for input
'-is the ' size ' of the ' string in characters
'--' M ' is a arbitrary initial value for this parameter

CmdSP.Parameters.Append cmdsp.createparameter ("@au_lname", adVarChar, adParamInput, "M")


'--Define the Parameter-the one, the procedure would 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



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.