ASP常用函数收藏乱七八糟未整理版(67)
SQL = "Select * FROM SecurityLevel Where UID="" & UserID & """
SQL = SQL & " AND PWD="" & Password & """
因为你的SQL将会是这样:
Select * FROM SecurityLevel Where UID="1"test" AND PWD="A|&900"
在SQL中,"|"为分割字段用的,显然会出错了。现在提供下面的几个函数 专门用来处理这些头疼的东西:
Quoted from Unkown:
<%
Function ReplaceStr (TextIn, ByVal SearchStr As String, _
ByVal Replacement As String, _
ByVal CompMode As Integer)
Dim WorkText As String, Pointer As Integer
If IsNull(TextIn) Then
ReplaceStr = Null
Else
WorkText = TextIn
Pointer = InStr(1, WorkText, SearchStr, CompMode)
Do While Pointer > 0
WorkText = Left(WorkText, Pointer - 1) & Replacement & _
Mid(WorkText, Pointer + Len(SearchStr))
Pointer = InStr(Pointer + Len(Replacement), WorkText, SearchStr, CompMode)
Loop
ReplaceStr = WorkText
End If
End Function
Function SQLFixup(TextIn)
SQLFixup = ReplaceStr(TextIn, """, """", 0)
End Function
Function JetSQLFixup(TextIn)
Dim Temp
Temp = ReplaceStr(TextIn, """, """", 0)
JetSQLFixup = ReplaceStr(Temp, "|", "" & Chr(124) & "", 0)
End Function
Function FindFirstFixup(TextIn)
Dim Temp
Temp = ReplaceStr(TextIn, """, "" & chr(39) & "", 0)
FindFirstFixup = ReplaceStr(Temp, "|", "" & Chr(124) & "", 0)
End Function
内容版权声明:除非注明,否则皆为本站原创文章。