OVH Cloud OVH Cloud

Pb de string

4 réponses
Avatar
Alain MENARD
salut,

Une requête plante à cause d'une apostrophe.

option explicit
Private vTheme As String
...

Private Sub Liste_ItemClick(ByVal item As MSComctlLib.ListItem)
vTheme = Liste.SelectedItem
End Sub

Private Sub SupprimerTheme_Click()
...
Set rstItemListe = New ADODB.Recordset
strSQL2 = "Delete * From themes where [Theme]='" & vTheme & "'"
...

hors le texte est (toute la ligne suivante) :
Arts : Arts et métiers d'art

Une idée ? Merci !
--

Amicalement

Alain

Pour me joindre : amenard@vision-tech.fr

4 réponses

Avatar
François Picalausa
Bonjour/soir

Essaye comme ceci:

strSQL2 = "Delete * From themes where [Theme]='" & Replace(vTheme,"'","''")
& "';"

--
François Picalausa (MVP VB)
FAQ VB : http://faq.vb.free.fr
MSDN : http://msdn.microsoft.com


Alain MENARD wrote:
salut,

Une requête plante à cause d'une apostrophe.

option explicit
Private vTheme As String
...

Private Sub Liste_ItemClick(ByVal item As MSComctlLib.ListItem)
vTheme = Liste.SelectedItem
End Sub

Private Sub SupprimerTheme_Click()
...
Set rstItemListe = New ADODB.Recordset
strSQL2 = "Delete * From themes where [Theme]='" &
vTheme & "'" ...

hors le texte est (toute la ligne suivante) :
Arts : Arts et métiers d'art

Une idée ? Merci !


Avatar
Alain MENARD
Super. C'est très bon à savoir cette astuce.

Merci François.

--

Amicalement

Alain

Pour me joindre :

"François Picalausa" a écrit dans le message de
news:%
Bonjour/soir

Essaye comme ceci:

strSQL2 = "Delete * From themes where [Theme]='" &


Replace(vTheme,"'","''")
& "';"

--
François Picalausa (MVP VB)
FAQ VB : http://faq.vb.free.fr
MSDN : http://msdn.microsoft.com


Alain MENARD wrote:
> salut,
>
> Une requête plante à cause d'une apostrophe.
>
> option explicit
> Private vTheme As String
> ...
>
> Private Sub Liste_ItemClick(ByVal item As MSComctlLib.ListItem)
> vTheme = Liste.SelectedItem
> End Sub
>
> Private Sub SupprimerTheme_Click()
> ...
> Set rstItemListe = New ADODB.Recordset
> strSQL2 = "Delete * From themes where [Theme]='" &
> vTheme & "'" ...
>
> hors le texte est (toute la ligne suivante) :
> Arts : Arts et métiers d'art
>
> Une idée ? Merci !




Avatar
blancmunier1
essaie

strSQL2 = "Delete * From themes where [Theme]='" & vTheme & "'"

avec :
Public Function EnleverCotes(s As Variant) As String
Dim nbCarIni As Integer
Dim I As Integer

nbCarIni = Len(s)
EnleverCotes = s
For I = 1 To nbCarIni
If Right(Left(s, I), 1) = "'" Then
EnleverCotes = Left(s, I - 1) & "'||Chr(39)||'" & Right(s, nbCarIni - I)
End If
Next I
End Function

ca marche sous Oracle...(ms peut-être pr tout SGBD)
sous access je crois qu'il faut doubler la cote,
dc :

Public Function EnleverCotes(s As Variant) As String
Dim nbCarIni As Integer
Dim I As Integer

nbCarIni = Len(s)
EnleverCotes = s
For I = 1 To nbCarIni
If Right(Left(s, I), 1) = "'" Then
EnleverCotes = Left(s, I - 1) & "''" & Right(s, nbCarIni - I)
End If
Next I
End Function

Yvan
Avatar
Alain MENARD
Merci. encore très bien

--

Amicalement

Alain

Pour me joindre :

"Bluesy @caramail.com>" <bluesy49<ANTISPAM> a écrit dans le message de
news:
Bonjour Alain

Voiçi une ch'tite fonction maison, que j'utilise systématiquement dès que


du
SQL entre en jeu

Public Function DoubleQuote(ByVal Chaine As String) As String
Chaine = Replace$(Chaine, Chr$(39), Chr$(39) & Chr$(39))
Chaine = Replace$(Chaine, Chr$(34), Chr$(34) & Chr$(34))
DoubleQuote = Chaine
End Function

Ca gère les cotes et les guillemets... comme ça, pas de souci...

Bonne prog à toi :=)

Bluesy

Un certain Alain MENARD écrivait ici même ce qui suit:

> salut,
>
> Une requête plante à cause d'une apostrophe.
>
> option explicit
> Private vTheme As String
> ...
>
> Private Sub Liste_ItemClick(ByVal item As MSComctlLib.ListItem)
> vTheme = Liste.SelectedItem
> End Sub
>
> Private Sub SupprimerTheme_Click()
> ...
> Set rstItemListe = New ADODB.Recordset
> strSQL2 = "Delete * From themes where [Theme]='" & vTheme &
> "'" ...
>
> hors le texte est (toute la ligne suivante) :
> Arts : Arts et métiers d'art
>
> Une idée ? Merci !