ASP & porcedure

Source: Internet
Author: User
Tags dsn

<%
Set conn = server. Createobject ("ADODB. Connection ")
Set cmd = server. Createobject ("ADODB. Command ")
Strconn = "DSN = pubs; uid = sa; PWD"
Conn. Open strconn
Set cmd. activeconnection = Conn
 
Cmd. commandtext = "{call Nono }"
 
'Set rsw.cmc.exe cmd.exe cute
 
Set rs = cmd. Execute ()
 
%>

2. Stored Procedure of an input parameter

<%
Set conn = server. Createobject ("ADODB. Connection ")
Set cmd = server. Createobject ("ADODB. Command ")
Strconn = "DSN = pubs; uid = sa; PWD"
 
Conn. Open strconn
Set cmd. activeconnection = Conn
 
Cmd. commandtext = "{call oneinput (?)} "
Cmd. Parameters. append cmd. createparameter ("@ AAA", adinteger, adparaminput)
CMD ("@ AAA") = 100
 
Cmd. Execute ()
 
%>

3. One input parameter and one output parameter

<%
Set conn = server. Createobject ("ADODB. Connection ")
Set cmd = server. Createobject ("ADODB. Command ")
Strconn = "DSN = pubs; uid = sa; PWD"
 
Conn. Open strconn
Set cmd. activeconnection = Conn
 
Cmd. commandtext = "{call oneinout (?,?)} "
Cmd. Parameters. append cmd. createparameter ("@ AAA", adinteger, adparaminput)
CMD ("@ AAA") = 10
Cmd. Parameters. append cmd. createparameter ("@ BBB", adinteger, adparamoutput)
 
Cmd. Execute ()
 
Bbb = cmd ("@ BBB ")
%>

4. One input parameter, one output parameter, and one return value

<%
Set conn = server. Createobject ("ADODB. Connection ")
Set cmd = server. Createobject ("ADODB. Command ")
Strconn = "DSN = pubs; uid = sa; PWD"
 
Conn. Open strconn
Set cmd. activeconnection = Conn
 
Cmd. commandtext = "{? = Call onereturn (?,?)} "
 
Cmd. Parameters. append cmd. createparameter ("@ return_value", adinteger, adparamreturnvalue)
Cmd. Parameters. append cmd. createparameter ("@ AAA", adinteger, adparaminput)
CMD ("@ AAA") = 10
Cmd. Parameters. append cmd. createparameter ("@ BBB", adinteger, adparamoutput)
 
Cmd. Execute ()
 
Bbb = cmd ("@ BBB ")
RRR = cmd ("@ return_value ")
%>?

How to call SQL stored procedures in ASP

<% Set connection1 = server. Createobject ("ADODB. Connection ")
Connection1.open... 'connection
Set command1 = server. Createobject ("ADODB. Command ")
Set command1.activeconnection = connection1
Command1.commandtype = 4
Command1.commandtext = "sp_1" 'SP name
Command1.parameters (1) =... 'parameter value
Command1.parameters (2) =...
Set recordset11_command1.exe cute ()
%>?

Skills for ASP to call stored procedures

1. The simplest is as follows:

Dim objconn
Set objconn = server. Createobject ("adobd. Connection ")
Objconn. open application ("connection_string ")
'Call the stored procedure to increment a counter on the page
Objconn. Execute "Exec sp_addhit"

No parameter, no response, no error handling.

2. A call with Parameters

Objconn. Execute "Exec sp_addhit 'HTTP: // www.aspalliance.com ', 1"

Note that the splitting parameter is not returned.
 
3.

Dim objconn
Dim objrs
Set objconn = server. Createobject ("adobd. Connection ")
Set objrs = server. Createobject ("adobd. recordset ")
Objconn. open application ("connection_string ")
'Call the stored procedure to increment a counter on the page
Objrs. Open objconn, "Exec sp_listarticles '2017/123 '"
'Loop through recordset and display each article

4 ,......

Dim objconn
Dim objcmd

'Instantiate objects
Set objconn = server. Createobject ("ADODB. Connection ")
Set objcmd = server. Createobject ("ADODB. Command ")
Conn. open application ("connectionstring ")

With objcmd
. Activeconnection = conn' you can also just specify a connection string here
. Commandtext = "sp_insertarticle"
. Commandtype = admo-storedproc 'requires the adovbs. inc file or typelib meta tag

'Add input parameters
. Parameters. append. createparameter ("@ columnist_id", addouble, adparaminput, columnist_id)
. Parameters. append. createparameter ("@ URL", advarchar, adparaminput, 255, URL)
. Parameters. append. createparameter ("@ title", advarchar, adparaminput, 99, URL)
. Parameters. append. createparameter ("@ description", adlongvarchar ,_
Adparaminput, 2147483647, description)

'Add output parameters
. Parameters. append. createparameter ("@ link_id", adinteger, adparamoutput, 0)

'Execute the Function
'If not returning A recordset, use the adexecutenorecords parameter Option
. Execute, adexecutenorecords
Link_id =. parameters ("@ link_id ")
End

5. Stored ProcedureCode

Create procedure DBO. sp_insertarticle
(
@ columnist_id int,
@ URL varchar (255),
@ title varchar (99 ),
@ description text
@ link_id int output
)
as
begin
insert into DBO. t_link (columnist_id, URL, title, description)
values (@ columnist_id, @ URL, @ title, @ description)
select @ link_id = @ identity
end

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.