Asp :数据库基本连接\解析 , 及捕捉错误输出.....

时间:2022-07-22 21:59:48
SqlConnection.asp :数据库connect
<%
  
Function  Open_conn()  
  
dim  Conn,Strconn 
  
set  Conn = server.createobject( " adodb.connection "
  Strconn 
=   " Provider=SQLOLEDB;Server=xiao;Database=piao;Uid=sa;Pwd=; "  
  Conn.open Strconn 
  
set  Open_conn = Conn 
  
If  Err  Then  
  err.Clear 
  Conn.close:
set  Conn = nothing  
  Response.Write 
" 对不起,服务器端数据库连接出错,请联系管理员! "  
  Response.End  
  
End   If  
  
End Function  
%>

输出错误:showmsg.asp

<%

sub  errshow(errmsg)
    tempstr
= " <script language=""JavaScript"" type=""text/JavaScript""> "
    tempstr
= tempstr & " alert("" " & errmsg & " ""); "
    tempstr
= tempstr & " history.back(); "
    tempstr
= tempstr & " </script> "
    response.Write(tempstr)
    response.End()
end sub

sub  successshow(errmsg,a)
    tempstr
= " <script language=""JavaScript"" type=""text/JavaScript""> "
    tempstr
= tempstr & " alert("" " & errmsg & " ""); "
    tempstr
= tempstr & " history.go("" " & a & " ""); "
    tempstr
= tempstr & " </script> "
    response.Write(tempstr)
    response.End()
end sub

%>

Pager.asp :数据表的分页.
<%  
function  pageturn(pageno,pagesize,rscount,strsearch)
 
    
dim  pagecount
    iCount
= rscount  \  pagesize
    
if  rscount > 0   and  rscount  mod  pagesize > 0   then  iCount = iCount + 1
    pagecount
= iCount
    
' if pagecount<2 then
         ' response.write "&nbsp;"
         ' exit function
     ' end if
    pageno = cint (pageno)
    
if  rscount = 0   then  pageno = 0

    response.Write(
" 共计 " & pagecount & " " )
    response.write(
" &nbsp;&nbsp; " )
    response.Write(
" " & pageno & " " )
    response.write(
" &nbsp;&nbsp; " )
    response.Write(
" 每页 " & pagesize & " 条信息 " )
    response.write(
" &nbsp;&nbsp; " )
    response.Write(
" 共计 " & rscount & " 条信息 " )
    response.write(
" &nbsp; &nbsp; " )
    response.Write(
" <a class='lianjie1' href='?pageno=1& " & strsearch & " '>首页</a> " )
    response.write(
" &nbsp;&nbsp; " )
    
    
    
if  pageno = 1   or  rscount = 0   then
        Response.Write(
" 上一页 " )
    
else
        Response.Write(
" <a class='lianjie1' href='?pageno= " & pageno - 1 & " & " & strsearch & " '>上一页</a> " )
    
end   if
    
    response.write(
" &nbsp;&nbsp; " )


    pageno_star
= pageno - 2
    pageno_over
= pageno + 2
    
    
if  pageno_star <= 1   then  
        
for  i = 1   to  pagecount
            
if  i <= 5   then  
                
if  i = pageno  then
                Response.Write(
" &nbsp;<strong> " & i & " </strong>&nbsp; " )
                
else
                Response.Write(
" &nbsp;<a class='lianjie1' href='?pageno= " & i & " & " & strsearch & " '> " & i & " </a>&nbsp; " )
                
end   if
            
end   if  
        
next
        
if  pagecount > 5   then  response.Write( " " )
    
elseif  pageno_over >= pagecount  then  
        response.Write(
" " )
        
for  i = pagecount - 5   to  pagecount

                
if  i = pageno  then
                Response.Write(
" &nbsp; " & i & " &nbsp; " )
                
else
                Response.Write(
" &nbsp;<a class='lianjie1' href='?pageno= " & i & " & " & strsearch & " '> " & i & " </a>&nbsp; " )
                
end   if

        
next         
    
else
        response.Write(
" " )
        
for  i = pageno_star  to  pageno_over

            
if  i = pageno  then
            Response.Write(
" &nbsp; " & i & " &nbsp; " )
            
else
            Response.Write(
" &nbsp;<a class='lianjie1' href='?pageno= " & i & " & " & strsearch & " '> " & i & " </a>&nbsp; " )
            
end   if

        
next     
        response.Write(
" " )
    
end   if  
    
    
    
    
    
    response.write(
" &nbsp;&nbsp; " )
    
    
if  pageno = pagecount  or  rscount = 0   then
        Response.Write(
" 下一页 " )
    
else
        Response.Write(
" <a class='lianjie1' href='?pageno= " & cint (pageno + 1 ) & " & " & strsearch & " '>下一页</a> " )
    
end   if
    
    response.write(
" &nbsp;&nbsp; " )
    response.Write(
" <a class='lianjie1' href='?pageno= " & pagecount & " & " & strsearch & " '>尾页</a> " )

 
' pageturn=strtemp
end function
%>

serceat.asp 加密...
<%   
A_Key
= split ( " 46,39,63,90,81,71,53,24,18,99,11 " , " , " ' 定义密钥  
'
*********加密的过程*********  
Function  EnCrypt(m)  
if  m = ""   or   isnull (m)  then   exit   function  
Dim  strChar,iKeyChar,iStringChar,I  
k
= 0   
for  I  =   1   to   Len ( trim (m))  
iKeyChar 
= Cint (A_Key(k))  
iStringChar 
=   Asc ( mid (m,I, 99 ))  ' 获取字符的ASCII码值  
iCryptChar  =  iKeyChar  Xor  iStringChar  ' 进行异或运算
 
  
' 对密钥进行移位运算  
If  k < 5   Then   
k
= k + 1   
Else   
k
= 0   
End   If   

c
= c & chr (iCryptChar)  
next   
EnCrypt 
=  c  
End Function   




' *********解密的过程*********  
Function  DeCrypt(c)
if  c = ""   or   isnull (c)   then   exit   function   
Dim  strChar, iKeyChar, iStringChar, I  
k
= 0   
for  I  =   1   to   Len ( trim (c))  
iKeyChar 
= Cint (A_Key(k))  
iStringChar 
=   Asc ( mid (c,I, 99 ))
iDeCryptChar 
=  iKeyChar  Xor  iStringChar  ' 进行异或运算 
 
' 对密钥进行移位运算  
If  k < 5   Then   
k
= k + 1   
Else   
k
= 0   
End   If   
strDecrypted
= strDecrypted & Chr (iDeCryptChar)  
next   
DeCrypt
= strDecrypted  
End Function  
 
%>   

Rs.Open参数说明

在ASP中经常用Rs.Open sql,conn,1,1这样的方式打开数据库,但仍有一部分同行不知道这是嘛意思,现整理如下:

Rs.Open语法如下:rs.Open   Source,ActiveConnection,CursorType,LockType
Source为sql语句,ActiveConnection为数据库连接,CursorType是游标,LockType是数据锁定类型.
CursorType 

常量                                             说明                         
adOpenForwardOnly(值为0)     (默认值)打开仅向前类型游标。     
adOpenKeyset(值为1)               打开键集类型游标。    
adOpenDynamic(值为2)             打开动态类型游标。     
 adOpenStatic(值为3)               打开静态类型游标。     
   
-----------------------  
LockType   
    
   
常量   说明    
adLockReadOnly (值为1)  (默认值)只读   —   不能改变数据。     
adLockPessimistic(值为2)   保守式锁定(逐个)   —   提供者完成确保成功编辑记录所需的工作,通常通过在编辑时立即锁定数据源的记录来完成。     
adLockOptimistic(值为3)   开放式锁定(逐个)   —   提供者使用开放式锁定,只在调用   Update   方法时才锁定记录。     
adLockBatchOptimistic(值为4)   开放式批更新   —   用于批更新模式(与立即更新模式相对)。    

CursorType
0             仅向前游标,只能向前浏览记录,不支持分页、Recordset、BookMark  
1             键集游标,其他用户对记录说做的修改将反映到记录集中,但其他用户增加或删除记录不会反映到记录集中。支持分页、Recordset、BookMark  
2             动态游标功能最强,但耗资源也最多。用户对记录说做的修改,增加或删除记录都将反映到记录集中。支持全功能浏览。  
3             静态游标,只是数据的一个快照,用户对记录说做的修改,增加或删除记录都不会反映到记录集中。支持向前或向后移动   
    
LockType      
    LockType为记录集的锁定类型,其取值为:  
  1             锁定类型,默认的,只读,不能作任何修改  
  2             当编辑时立即锁定记录,最安全的方式  
  3             只有在调用Update方法时才锁定记录集,而在此前的其他操作仍可对当前记录进行更改、插入和删除等  
  4             当编辑时记录不会被锁定,而更改、插入和删