ASP 数据库连接字符串(使用DSN)

<%
	'Open the database connection
	Set objConn = Server.CreateObject("ADODB.Connection")
	objConn.Open "DSN=dsn_name;UID= ;PWD= "
%>

ASP ASP替换子程序

address = Replace(address, """", "'")

ASP 查找页面文件名的功能

Function getFileName()
    Dim lsPath, arPath
    'Obtain the virtual file path
    lsPath = Request.ServerVariables("SCRIPT_NAME")
    'Split the path along the /s. This creates a one-dimensional array
    arPath = Split(lsPath, "/")
    'The last item in the array contains the file name
    getFileName = arPath(UBound(arPath,1))
End Function

ASP ASP没有缓存

<%
pStr = "private, no-cache, must-revalidate no-store pre-check=0 post-check=0 max-stale=0" 
Response.ExpiresAbsolute = #2000-01-01# 
response.AddHeader "Pragma", "no-cache"
response.AddHeader "cache-control", pStr
%>

ASP ASP - Pintar str buscado

function pintar( q, str )
	Set regEx = New RegExp
	regEx.Pattern = q
	regEx.IgnoreCase = True
	regEx.Global = True
	TextosResultado = regEx.Replace(str, "<font style=""background-color:#FAEEEF"">"& q &"</font>")
	pintar = TextosResultado
end function

ASP ASP - Eregi Para Regex

Function eregi(ByVal str, ByVal patrn,ByVal rpl)
'EJ, para sacar tags eregi(texto,"<([^>]+)>","")
'Ej, para sacar los links eregi(texto,"<a([^>]+)>|</a>","")
		 Set regEx = New RegExp
		 regEx.Pattern = patrn
		 regEx.IgnoreCase = True
		 regEx.Global = True
		 StrReplace = regEx.Replace(str,rpl)
		eregi = StrReplace
End function

ASP UrlDecode方法

' An inverse to Server.URLEncode
function URLDecode(str)
	dim re
	set re = new RegExp

	str = Replace(str, "+", " ")
	
	re.Pattern = "%([0-9a-fA-F]{2})"
	re.Global = True
	URLDecode = re.Replace(str, GetRef("URLDecodeHex"))
end function

' Replacement function for the above
function URLDecodeHex(match, hex_digits, pos, source)
	URLDecodeHex = chr("&H" & hex_digits)
end function

ASP openDB

function openDB()
	dim conn
	set conn = server.createobject("ADODB.Connection")
	conn.open "PROVIDER=SQLOLEDB;DATA SOURCE=;UID=;PWD=;DATABASE="
	openDB = conn
end function

ASP 交替的行颜色

Dim sBgcolor
        
        if (i mod 2 = 0) then
            sBgcolor = "#eee"
        else    
            sBgcolor = "#fff"
        end if
	
        <tr style="background-color:<%=sBgcolor%>;" onMouseOver="this.style.background='#ddd;'" onMouseOut="this.style.background='<%=sBgcolor%>;'">

ASP breadCrumbs(递归)

sub getChildren(rowId)
    Dim sSQL,oRS,itemArray,i
    sSQL = "SELECT rowId,rowName,parent_id from table WHERE parent_id = " & rowId
    set oRS = cn.execute(sSQL)
    itemArray = oRS.getRows()
    
    if isArray(itemArray) then
        dim rowId,rowName,parent_id
    	for i = 0 to ubound(itemArray,2)
            rowId = itemArray(0,i)
            rowName = itemArray(1,i)
            parent_id = itemArray(2,i)
            
            call getChildren(parent_id) 'pass in parent id here
            
            response.write " >> <a href=""page.asp?p="&rowId&""">"&rowName&"</a>"

         next
    end if
end sub