Recommended: Implementation of asp batch data entry Batch entry is widely used in databases, and there are many methods for batch entry. Next, I will talk about how I achieved it based on my actual application. The main use is the concept of form collection, which takes all the data in the collection through loop. Considering that it is convenient for everyone to see, I integrated it into one page. Below is the specific code
Several ways to call stored procedures with parameters
1 This is also the easiest method, with two input parameters, no return value:
set connection = server.createobject(adodb.connection)
connection.open someDSN
Connection.Execute procname varvalue1, varvalue2
'Clear all objects into nothing, free up resources
connection.close
set connection = nothing
2 If you want to return the Recordset set:
set connection = server.createobject(adodb.connection)
connection.open someDSN
set rs = server.createobject(adodb.recordset)
rs.Open Exec procname varvalue1, varvalue2,connection
'Clear all objects into nothing, free up resources
rs.close
connection.close
set rs = nothing
set connection = nothing
3 The above two methods cannot have a return value (except Recordset). If you want to get the return value, you need to use the Command method.
First of all, there are two types of return values. One is to directly return a value in the stored procedure, just like the functions of C and VB return values; the other is to return multiple values,
The variable names that store these values need to be specified first in the call parameter.
This example will deal with multiple parameters, input parameters, output parameters, return recordsets and a direct return value (is it all enough?)
The stored procedure is as follows:
use pubs
GO
-- Create stored procedures
create procedure sp_PubsTest
-- Define three parameter variables, note the third one, the special mark is used for output
@au_lname varchar (20),
@intID int,
@intIDOut int OUTPUT
AS
SELECT @intIDOut = @intID 1
SELECT *
FROM authors
WHERE au_lname LIKE @au_lname '%'
--Return a value directly
RETURN @intID 2
The asp program that calls the stored procedure is as follows:
<%@ Language=VBScript %>
<%
Dim CmdSP
Dim adoRS
Dim adCmdSPStoredProc
Dim adParamReturnValue
Dim adParaminput
Dim adParamOutput
Dim adInteger
Dim iVal
Dim oVal
Dim adoField
Dim adVarChar
'These values are predefined constants in VB and can be called directly, but not predefined in VBScript
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)
'Create a link
CmdSP.ActiveConnection = Driver={SQL Server};server=(local);Uid=sa;Pwd=;Database=Pubs
'Define the command object call name
CmdSP.CommandText = sp_PubsTest
'Set command call type as a stored procedure (adCmdSPStoredProc = 4)
CmdSP.CommandType = adCmdSPStoredProc
'Add parameters to the command object
'Define the stored procedure has a direct return value, and is an integer, the default value is 4
CmdSP.Parameters.Append CmdSP.CreateParameter(RETURN_VALUE, adInteger, adParamReturnValue, 4)
'Define a character input parameter
CmdSP.Parameters.Append CmdSP.CreateParameter(@au_lname, adVarChar, adParaminput, 20, M)
'Define an integer input parameter
CmdSP.Parameters.Append CmdSP.CreateParameter(@intID, adInteger, adParamInput, , iVal)
'Define an integer output parameter
CmdSP.Parameters.Append CmdSP.CreateParameter(@intIDOut, adInteger, adParamOutput, oVal)
'Run the stored procedure and get the return record set
Set adoRS = CmdSP.Execute
'Print out each record, the fields in which are virtual, you can ignore it
While Not adoRS.EOF
for each adoField in adoRS.Fields
Response.Write adoField.Name & = & adoField.Value & <br> & vbCRLF
Next
Response.Write <br>
adoRS.MoveNext
Wend
'Print two output values:
Response.Write <p>@intIDOut = & CmdSP.Parameters(@intIDOut).Value & </p>
Response.Write <p>Return value = & CmdSP.Parameters(RETURN_VALUE).Value & </p>
'Big cleaning
Set adoRS = nothing
Set CmdSP.ActiveConnection = nothing
Set CmdSP = nothing
%>
There are other ways, which are a little bit off, and I will talk about it later
This article has referenced many articles, and will not be listed here.
Share: Multiple repeated submissions of restricted forms in ASP On the Internet, we encounter countless forms every day, and we also see that most of them do not restrict users from submitting the same form multiple times. The lack of such restrictions can sometimes produce some unexpected results, such as duplicate subscription to email services or duplicate voting. This article introduces a simple method in ASP applications to prevent users from submitting the same form multiple times during the current session