Implementation example of asp mssql Stored Procedure

Source: Internet
Author: User

SQL CopyCode The Code is as follows: Create procedure proname // use create procedure to create a stored procedure proname as the stored procedure name
@ Lname varchar (30) // defines the input parameter
As
Set nocount on
Begin
Select * From tablename where lname like '%' + @ lname + '%' // use selece to fuzzy query all rows whose lname value is similar to the value of the input parameter lname
End
Go

A stored procedure with an input parameter has been created and a record set of all queries is returned.
The following describes how to use ASP to operate the stored procedure.Copy codeThe Code is as follows: // The following is a string that establishes a connection with MSSQL Server. As we all know, I will not talk about it.
Strconnect = "driver = {SQL Server}; server = (local); uid = sa; Password =; database = 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 is the connection string
Cmd. commandtext = "proname" // The Name Of The stored procedure to be used.
Cmd. commandtype = 4 // The commandtype attribute indicates the request type.
//-1 indicates that the commandtext parameter type cannot be determined
// 1 indicates that commandtext is a common command type
// 2 indicates that the commandtext parameter is an existing table name.
// 4 indicates that the commandtext parameter is the name of a stored procedure, so commandtype = 4 here.
Cmd. Prepared = true // requires that the SQL command be compiled first
Cmd. Parameters. append cmd. createparameter ("@ lname", 4, lname) // Add the @ lname parameter. The lname following the parameter is the variable defined on the ASP page.
Set rs = cmd. Execute // set the RS variable to retrieve the returned query record set.
End

Do while not Rs. EOF // use do loop to read the rows in the RS record set
Response. Write (RS ("field name") "<br/> ")
Rs. movenext // move to the next
Loop // end Loop

Rs. Close // close the object

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.