Tutorials to .com

Tutorials to .com » Asp » Fso » Commonly used ASP function

Commonly used ASP function

Print View , by: iSee ,Total views: 25 ,Word Count: 630 ,Date: Thu, 16 Apr 2009 Time: 4:52 AM

Commonly used asp function, of a hope that can be used.

<%
dim db
db = "dbms.mdb"

'************************************************* *****************
'The implementation of sql statement does not return value, sql statement is the best are as follows:
'update table set field name = value, field name field = value where name = value
'delete from table name where field name = value
'insert into table (field names, field names) values (value, value)
'************************************************* *****************
Sub NoResult (sql)
dim conn
dim connstr
Set conn = Server.CreateObject ( "ADODB.Connection")
connstr = "Provider = Microsoft.Jet.OLEDB.4.0; Data Source =" & Server.MapPath ( "" & db & "")
conn.Open connstr
conn.execute sql
conn.close
set conn = nothing
End Sub

'************************************************* ******************
'The implementation of select statement to return recordset object. The object read-only. That is, can not be updated
'************************************************* ******************
Function Result (sql)
dim conn
dim connstr
dim rcs
Set conn = Server.CreateObject ( "ADODB.Connection")
connstr = "Provider = Microsoft.Jet.OLEDB.4.0; Data Source =" & Server.MapPath ( "" & db & "")
conn.Open connstr
Set rcs = Server.CreateObject ( "ADODB.Recordset")
rcs.open sql, conn, 1,1
set Result = rcs
End Function

'************************************************* ******************
'Pop-up dialog box
'************************************************* ******************
Sub alert (message)
message = replace (message ,"'"," \ ' ")
Response.Write ( "<script> alert ( '" & message & "')</ script> ")
End Sub

'************************************************* ******************
'Return to the previous page, which tends to be used in determining whether the information submitted after the
'************************************************* ******************
Sub GoBack ()
Response.write ( "<script> history.go (-1) </ script>")
End Sub

'************************************************* ******************
'Redirect the other to connect
'************************************************* ******************
Sub Go (url)
Response.write ( "<script> location.href ( '" & url & "')</ script> ")
End Sub

'************************************************* ******************
'To replace html tag
'************************************************* ******************

function htmlencode2 (str)
dim result
dim l
if isNULL (str) then
htmlencode2 = ""
exit function
end if
l = len (str)
result = ""
dim i
for i = 1 to l
select case mid (str, i, 1)
case "<"
result = result + "<"
case ">"
result = result + ">"
case chr (13)
result = result + "<br>"
case chr (34)
result = result + "" "
case "&"
result = result + "&"
case chr (32)
'result = result + ""
if i +1 <= l and i-1> 0 then
if mid (str, i +1,1) = chr (32) or mid (str, i +1,1) = chr (9) or mid (str, i-1, 1) = chr (32) or mid (str, i-1, 1) = chr (9) then
result = result + ""
else
result = result + ""
end if
else
result = result + ""
end if
case chr (9)
result = result + ""
case else
result = result + mid (str, i, 1)
end select
next
htmlencode2 = result
end function

'************************************************* ******************
'Sql string to check whether there are single quotes, I would be transformed into
'************************************************* ******************
function CheckStr (str)
dim tstr, l, i, ch
str = Trim (str)
l = len (str)
for i = 1 to l
ch = mid (str, i, 1)
if ch = " '" then
tstr = tstr + " '"
end if
tstr = tstr + ch
next
CheckStr = tstr
end function
%>


ASP File System Object Articles


Can't Find What You're Looking For?


Rating: Not yet rated

Comments

No comments posted.