Practical Web Programming

Saturday, January 05, 2008

How To Pair a Single Quote, Useful for SQL Queries and Statements

This function will ensure that a single qoute(') is paired. This is useful when executing SQL queries because an unpaired qoute(') will spit an SQL error in all database engine.

This source codes is written in Visual Basic 6.

Public Function BalanceQoute(sText As String) As String
Dim sSavar As String, i As Integer
sSavar = ""
For i = 1 To Len(Trim(IfNull(sText)))
If Mid(sText, i, 1) <> "'" Then
sSavar = sSavar + Mid(sText, i, 1)
sSavar = sSavar + "''"
End If
Next i
ChkValue = sSavar
End Function


Recent Post