Implementation of ASP-based storage procedures for ASPs Small example _ application skills

Source: Internet
Author: User
Sql
Copy Code code as follows:

Create PROCEDURE Proname//Creating a stored procedure by using the Create PROCEDURE proname for the stored procedure name
@Lname VARCHAR (30)//define incoming parameters
As
SET NOCOUNT on
BEGIN
SELECT * FROM tablename WHERE Lname like '% ' + @Lname + '% '///Use selece fuzzy query Lname value is similar to the value of the passed-in parameter Lname all rows
End
Go

The above is a stored procedure with one input parameter has been created, and the demerit sets for all queries are returned.
This stored procedure is now being manipulated using ASP.
Copy Code code as follows:

Here is a string to establish a connection with MSSQL server, as you all know, I will not speak.
strconnect = "Driver={sql Server}"; server= (local); uid=sa;password=;d Atabase=dataname "
Set conn = server. CreateObject ("Adodb.connection")
Conn. Open strconnect

Set cmd = Server.CreateObject ("Adodb.command")//Create a Command object
With cmd
Cmd. ActiveConnection = conn//conn for connection string
Cmd.commandtext = "Proname"//Here is the name of the stored procedure to use
Cmd.commandtype = 4//commandtype property indicates the type of request.
-1 indicates that the type of the CommandText parameter cannot be determined
1 indicates that CommandText is a generic command type
2 indicates that the CommandText parameter is a table name that exists
4 indicates that the CommandText parameter is the name of a stored procedure, so here CommandType = 4.
Cmd. Prepared = TRUE//requires that SQL commands be compiled first
Cmd. Parameters.Append cmd. CreateParameter ("@Lname", 3,1,4,lname)//Add parameter @lname, the Lname behind is the variable that you define in the ASP page.
Set rs = cmd. Execute//Set RS variable to get the returned query record set.
End With

Do but not Rs. EOF//Read the line in the RS recordset with Do Loop
RESPONSE. WRITE (RS (field name) "<br/>")
Rs. MOVENEXT//Move to the next one
Loop//End loop

Rs. Close//Off objects

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.