ASP calls stored procedures!

xiaoxiao2021-03-06  129

1. The general method of calling the stored procedure first assumes that there is a stored procedure DT_USERS: CREATE Procedure [DBO] in SQL Server, [dt_users] As SELECT *, the first method is not using the Command object, directly with the Recordset object set RS = Server.createObject ("AdoDb.Recordset") SQL = "Exec DT_USERS" RS.Open SQL, CONN, 1, 1 This is the second method to use the Command object set comm = server.createObject ("AdoDb.command ") Comm.commantype = 4 set comm.activeconnection = conncommmmandtext =" dbo.dt_users "set = server.createObject (" adoDb.recordset ") rs.open comm, 1, 1

2. Transfer parameters to the stored procedure If the parameters do not need during the stored procedure, but a single SQL statement, it also displays the advantages of no adjustment stored procedures! For example, a BBS query can be inquired by the author and theme! The stored procedure can be established as follows: Parameter Keyword is keyword, and Choose is the method of selecting queries. CREATE PROCEDURE [dbo]. [Dt_bbs] @keyword varchar (20) = null, @choose int = null as if @ choose = 1 select * from bbs where name like @keyword else select * from bbs where subject like @keyword return go This way we call the stored procedure, just pass the parameters, and save the first method of writing a program in the ASP: SET RS = Server.createObject ("AdoDb.Recordset") SQL = "EXEC DT_BBS ' "& Keyword &" ', "& Choose &" RS.Open SQL, CONN, 1, 1 with the second method: set comm = server.createObject ("adoDb.command") comm.commantype = 4 comm.Parameters.Append Comm.Parameters.Append Comm.Parameters.Append Comm.Parameters.Append Comm.Parameters.Append Comm. CreateParameter ( "@ keyword", adChar, adParamInput, 50, keyword) comm.Parameters.append comm.CreateParameter ( "@ keyword", adInteger, adParamInput ,, choose) set comm.activeconnection = conn comm.commandtext = "dbo.dt_bbs "SET RS = Server.createObject (" AdoDb.Recordset ") rs.cursortype = 3 rs.Open Comm, 1, 1

转载请注明原文地址:https://www.9cbs.com/read-98100.html

New Post(0)