EscapeApos Function:
EscapeApos properly escapes varchar input for sql server as well as MS Access.
Description:
EscapeApos properly escapes strings for sql. EscapeApos automatically returns the surrounding "'" 's along with the escaped input.
Syntax:
escapedString = EscapeApos(inputString)
Details:
The following illustrates what is returned by the function for certain types of input:
Iinput: "my dog's fleas" Output: "my dog''s fleas"
Input: "" Output: "NULL"
Input: "flowers and candy" Output: "flowers and candy"
Example:
<%
dim name, id, sql, c
'--- escape string name = EscapeApos(Request("name"))
'--- ensure int id = CLng(Request("id"))
'--- build sql sql = "UPDATE table1 SET name = " & name & " WHERE ID = " & id
'--- execute sql Set c = CreateObject("ADODB.Connection") c.Open "connstring" c.Execute sql c.Close Set c = Nothing
%>
ASP Source Code:
<%
Function EscapeApos(ByVal input) If IsNull(input) Then EscapeApos = "NULL" Exit Function End If
If IsEmpty(input) then EscapeApos = "NULL" Exit Function End If
If Len(Trim(input)) = 0 Then EscapeApos = "NULL" Exit Function End If
EscapeApos = "'" & Replace(input, "'", "''") & "'" End Function
%>
|