Chức năng: Chuyển đổi ký tự dùng trong SQL
Ngôn ngữ: asp - Nhóm: database
CÚ PHÁP
escapedString = EscapeApos(inputString)
Chuyển đổi các ký tự như " thành các ký tự thích hợp khi thực hiện truy vấn SQL để tránh lổi.
VÍ DỤ
<%
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 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
%>