Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Inserting a string with an apostrophe
Message
Information générale
Forum:
Visual Basic
Catégorie:
Bases de données DAO/RDO/ODBC/ADO
Divers
Thread ID:
00568577
Message ID:
00568587
Vues:
19
This message has been marked as the solution to the initial question of the thread.
>I am doing an insert:
>
>sSql = "Insert " & _
> "Into GWC.Cert_Agnc_Hldr " & _
> "(agnc_num, hldr_name) " & _
> "Values('" & sAgncNum & "', '" & sDsplyName "')"
>
>The problem is that I ran across a value for sDsplyName that was: Mac's.
>when it runs into this particular value for name, it gives me an error because of the apostrophe. Is there any way to do this without removing the ' from Mac's?
>Thanks,
>Ryan Uhl

To what database are you inserting to? In SQL Server you can double up single quotes in SQL statements to get just one inserted, so you could probably check for the existence of them with Instr() and if there are then you can use Replace() to double them up before adding it to the sSql string like so:
If Instr(myValue, "'")<>0 Then
   myValue = Replace(myValue, "'", "''")
End If
sSql = .. etc.
If it isn't SQL Server then this might not work. HTH
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform