VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Clean Text before insertion into an SQL Server Database

by Jan Mohamed (1 Submission)
Category: Databases/Data Access/DAO/ADO
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Sat 1st February 2003
Date Added: Mon 8th February 2021
Rating: (1 Votes)

Clean Text before insertion into an SQL Server Database

Rate Clean Text before insertion into an SQL Server Database



'// This routine just cleans up any strings with offending characters like "'" which
'// cause a problem during an Execute method while updating a database table
'// the first argument is for the string to clean, the second argument is the
'// offending character

'// Author:   Jan Mohamed
'// Date:     2nd January 2003
'// Warning:  Author name must be retained (as if anyone is going to listen)
'//***************************************************************************

Public Function CleanText(ByVal sTextToClean As String, ByVal sBadText As String) As String

    Dim vPosition, lStart As Long
    
    CleanText = Trim(sTextToClean)
    lStart = 1
Start_Check:
    vPosition = InStr(lStart, CleanText, sBadText)
    
    If vPosition Then
        CleanText = Left(CleanText, vPosition) & sBadText & _
                    Mid(CleanText, vPosition + 1, Len(CleanText))
        lStart = vPosition + 2
        GoTo Start_Check
    End If
    

End Function


Download this snippet    Add to My Saved Code

Clean Text before insertion into an SQL Server Database Comments

No comments have been posted about Clean Text before insertion into an SQL Server Database. Why not be the first to post a comment about Clean Text before insertion into an SQL Server Database.

Post your comment

Subject:
Message:
0/1000 characters