ASP調用存講過程總結

1,執行帶參數的sql語句,返回集沒有pagecount,recordcount,pagesize等屬性.
sql="select * from table where UserName=? and UserPwd=?"
set conn=opendb()
Set cmd=Server.CreateObject("ADODB.Command")
with cmd
    .CommandTimeout   
= 1800
    .ActiveConnection 
= conn              'conn是聯接數據庫字符串
    .CommandText      = sql               '存儲過程名稱
    .CommandType      = 1                 '說明類型
    .Prepared         = true              '要求要命預編譯
    .Parameters.append .CreateParameter("@UserName",200,1,20,user_name)
    .Parameters.append .CreateParameter(
"@UserPwd",200,1,20,user_pwd)
    
Set rs=.Execute
end with
if not rs.eof then
  session(
"user_name")=user_name
  rdr
="url.asp"
else
  rdr
="login.asp"
  msg
="使用者帳號或密碼錯誤!"
end if
set cmd=nothing
rs.close():
set rs=nothing
conn.close():
set conn=nothing
'這种執行方式是帶參數的執行方式,返回的結果集是只向前的
'
,沒有recordcount,pagesize,pagecount屬性.
'
'

2,執行帶參數的sql語句,返回集有recordcount,pagecount,pagesize等屬性. 

<%
sql
="Select * from table WHERE answertime is not null and QA_ClassDetail_ID=?"&_
        
" ORDER BY AnswerTime desc,QALookNum"
this_pagesize
=page_qaNum
'建立物件
Set cmd=Server.CreateObject("ADODB.Command")
set conn=opendb()
with cmd
    .CommandTimeout   
= 1800
    .ActiveConnection 
= conn              'conn是聯接數據庫字符串
    .CommandText      = sql               '存儲過程名稱
    .CommandType      = 1                 '說明類型
    .Prepared         = true              '要求要命預編譯
    .Parameters.append .CreateParameter("@QA_ClassDetail_ID",3,1,4,id)
end with
Set rs = Server.CreateObject("ADODB.Recordset")
rs.open cmd,,
3
if not rs.eof then 
    rs.pagesize
=20
    allpage
=rs.pagecount
    
'對pagenum進行分析
    p=request("p")
    
if IsNumeric(p) then
        p
=cint(p)
        
if p>allpage then p=allpage
        
if p<=0 then p=1
    
else
        p
=1
    
end if
    
if p>0 then rs.absolutepage=p
    
for j=1 to this_pagesize
%
>
<a href="javascript:opencenterwin1('ViewAsk.asp?id=<%=rs("id")%>','VIEW',700,500);" title="<%=rs("qatitle")%>"><%=rs("qatitle")%></a>[<%=rs("qalookNum")%>]&nbsp;&nbsp;&nbsp;&nbsp;[回復日期:<%=Formatdatetime(rs("AnswerTime"),2)%>]<br>
<%   
        rs.movenext
        
if rs.eof then exit for
    
next
%
>
<!-- #include file="inc_page.asp"-->
<%
ELSE
%
>
<span style="text-align:center; 100%;">抱歉,暫無資料.</span>
<%
END IF

set cmd=nothing
rs.close():set rs=nothing

conn.close():set conn=nothing
%
>

3,執行帶參數的sql語句進行新增/編輯/刪除

sql="delete from table where id=?"
set conn=opendb()
Set cmd=Server.CreateObject("ADODB.Command")
with cmd
    .CommandTimeout   
= 1800
    .ActiveConnection 
= conn              'conn是聯接數據庫字符串
    .CommandText      = sql               '存儲過程名稱
    .CommandType      = 1                 '說明類型
    .Prepared         = true              '要求要命預編譯
    .Parameters.append .CreateParameter("@id",3,1,4,id)
    .Execute
end with
set cmd=nothing
conn.close():
set conn=nothing
http://www.cnblogs.com/Athrun/archive/2007/08/13/854494.html

申明

非源创博文中的内容均收集自网上,若有侵权之处,请及时联络,我会在第一时间内删除.再次说声抱歉!!!

博文欢迎转载,但请给出原文连接。

原文地址:https://www.cnblogs.com/Athrun/p/1333670.html