现在的位置: 首页 > 编程语言 > 正文

ASP调用sql server存储过程有哪些技巧

2020年06月02日 编程语言 ⁄ 共 509字 ⁄ 字号 评论关闭

  在asp程序中使用sqlserver存储过程是常见的事,主要的作用是提高程序运行的时间,这里介绍一下调用不同类型的存储过程的方法。下面学步园小编来讲解下ASP调用sqlserver存储过程有哪些技巧?

  ASP调用sqlserver存储过程有哪些技巧

  一、最简单的调用

  <%   DimobjConn   SetobjConn=Server.CreateObject("ADOBD.Connection")   objConn.OpenApplication("Connection_String")   'Callthestoredproceduretoincrementacounteronthepage   objConn.Execute"execsp_AddHit"   %>

  没有参数,没有返回,没有错误处理,就是这个了

  二、带参数的一种调用

  <%   objConn.Execute"execsp_AddHit,'http://www.aspbc.com',1"   %>

  注意分割参数,该方法也不返回记录

  ASP调用sqlserver存储过程有哪些技巧

  三、带返回记录集的

  <%   DimobjConn   DimobjRs   SetobjConn=Server.CreateObject("ADOBD.Connection")   SetobjRs=Server.CreateObject("ADOBD.Recordset")   objConn.OpenApplication("Connection_String")   'Callthestoredproceduretoincrementacounteronthepage   objRs.OpenobjConn,"execsp_ListArticles'1/15/2001'"   'Loopthroughrecordsetanddisplayeacharticle   %>

  四、带参数和返回记录集的

  <%   DimobjConn   DimobjCmd   'Instantiateobjects   SetobjConn=Server.CreateObject("ADODB.Connection")   setobjCmd=Server.CreateObject("ADODB.Command")   conn.OpenApplication("ConnectionString")   WithobjCmd   .ActiveConnection=conn'Youcanalsojustspecifyaconnectionstringhere   .CommandText="sp_InsertArticle"   .CommandType=adCmdStoredProc'Requirestheadovbs.incfileortypelibmetatag   '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   %>

  五、存储过程代码

  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

  以上就是关于“ASP调用sqlserver存储过程有哪些技巧”的内容,希望对大家有用。更多资讯请关注学步园。学步园,您学习IT技术的优质平台!

抱歉!评论已关闭.