Avatar of RIAS
RIAS
Flag for United Kingdom of Great Britain and Northern Ireland

asked on 

VB.net/SQL dealing with apostrophes in strings

Hi,
How Do I find the string has an apostrophe, single quote in the string.
I have a function
 Public Function ReplaceSingleQuote(ByRef val As String)
        '//***This function replaces the single quote to double quote***\\
        If IsNothing(val) = False OrElse val <> String.Empty Then
            val = val.Replace("'", "''")
            val = val.TrimStart
        End If
        Return val
    End Function

Open in new window

But, the problem here is that if use for multiple times for the same string it inserts too many single quotes.
Is there any way it just detects an single apostrophe and then replaces it with '' for sql compatibility.
Thanks
.NET ProgrammingVisual Basic.NETSQLMicrosoft Visual Studio

Avatar of undefined
Last Comment
RIAS

8/22/2022 - Mon