ASP调用存储过程的技巧

2018-09-06 11:06

阅读:434

  1、最简单的如下
DimobjConn
objConn.OpenApplication(Connection_String)
Callthestoredproceduretoincrementacounteronthepage
objConn.Executeexecsp_AddHit
没有参数,没有返回,没有错误处理,就是这个了

2、带参数的一种调用
objConn.Executeexecsp_AddHit,
请注意分割参数,该方法也不返回记录

3、返回记录的
DimobjConn
DimobjRs
SetobjConn=Server.CreateObject(ADOBD.Connection)
SetobjRs=Server.CreateObject(ADOBD.Recordset)
objConn.OpenApplication(Connection_String)
Callthestoredproceduretoincrementacounteronthepage
objRs.OpenobjConn,execsp_ListArticles1/15/2001
Loopthroughrecordsetanddisplayeacharticle
4、……
DimobjConn
DimobjCmd

Instantiateobjects
SetobjConn=Server.CreateObject(ADODB.Connection)
conn.OpenApplication(ConnectionString)

WithobjCmd
.ActiveConnection=connYoucanalsojustspecifyaconnectionstringhere
.CommandText=sp_InsertArticle

AddInputParameters
.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)

AddOutputParameters
.Parameters.Append.CreateParameter(@link_id,adInteger,adParamOutput,,0)

Executethefunction
Ifnotreturningarecordset,usetheadExecuteNoRecordsparameteroption
.Execute,,adExecuteNoRecords
link_id=.Parameters(@link_id)
EndWith

5、存储过程的代码
CreatePROCEDUREdbo.sp_InsertArticle
(
@columnist_idint,
@urlvarchar(255),
@titlevarchar(99),
@descriptiontext
@link_idintOUTPUT
)
AS
BEGIN
INSERTINTOdbo.t_link(columnist_id,url,title,description)
VALUES(@columnist_id,@url,@title,@description)

SELECT@link_id=@@IDENTITY
END


评论


亲,登录后才可以留言!