apex or apostrofis

L

Luca from Italy

Hello fro Italy, is there anyone who can help me here.
This is easy code for inserting data in our company questionnaire. The
problems comes when user inser a data with apostrophis. If he writes
"la casa" it works but if he writes "l'albero" the message gives error
because with apex in the string he can't recognize where the string
ends. How can I solve this problem?
This is code:

Dim cnn1 As New OleDb.OleDbConnection()
Dim str3 As String
'str3 = "insert into DATIQ
(GIUD,RICEV,SERV,QUALCUC,BUFFET,SERRIST,SERSP,MINI,ANIMD,ANIMS,PRENO,BENES,QP,CONS,TORN,OFFERTE,SUGG,HOTEL,NPRATICA,DAL,AL,VOLTA,GRAD,NGRAD)
values('" & giud.SelectedItem.Text & "','" & ricev.SelectedItem.Text &
"','" & serv.SelectedItem.Text & "','" & qualcuc.SelectedItem.Text &
"','" & buffet.SelectedItem.Text & "','" & serrist.SelectedItem.Text &
"','" & sersp.SelectedItem.Text & "','" & mini.SelectedItem.Text &
"','" & animd.SelectedItem.Text & "','" & anims.SelectedItem.Text &
"','" & preno.SelectedItem.Text & "','" & benes.SelectedItem.Text &
"','" & qp.SelectedItem.Text & "','" & cons.SelectedItem.Text & "','"
& torn.SelectedItem.Text & "','" & offerte.SelectedItem.Text & "','" &
sugg.Text & "','" & hotel.Text & "','" & npratica.Text & "','" &
dal.Text & "','" & al.Text & "','" & volta.SelectedItem.Text & "','" &
grad.Text & "','" & ngrad.Text & "')"
str3 = "insert into DATIQ
(GIUD,RICEV,SERV,QUALCUC,BUFFET,SERRIST,SERSP,MINI,ANIMD,ANIMS,PRENO,BENES,QP,CONS,TORN,OFFERTE,sugg,hotel,NPRATICA,DAL,AL,VOLTA,GRAD,NGRAD)
values('" & giud.SelectedItem.Text & "','" & ricev.SelectedItem.Text &
"','" & serv.SelectedItem.Text & "','" & qualcuc.SelectedItem.Text &
"','" & buffet.SelectedItem.Text & "','" & serrist.SelectedItem.Text &
"','" & sersp.SelectedItem.Text & "','" & mini.SelectedItem.Text &
"','" & animd.SelectedItem.Text & "','" & anims.SelectedItem.Text &
"','" & preno.SelectedItem.Text & "','" & benes.SelectedItem.Text &
"','" & qp.SelectedItem.Text & "','" & cons.SelectedItem.Text & "','"
& torn.SelectedItem.Text & "','" & offerte.SelectedItem.Text & "','" &
sugg.Text & "','" & hotel.Text & "','" & npratica.Text & "','" &
dal.Text & "','" & al.Text & "','" & volta.SelectedItem.Text & "','" &
grad.Text & "','" & ngrad.Text & "')"

RUNSQLSTRING(str3)


Private Sub RUNSQLSTRING(ByVal STR3 As String)
Dim cnn1 As New OleDb.OleDbConnection()
Dim str2 As String
str2 = "File name=c:\aurum.udl"
cnn1.ConnectionString = str2

Dim cmd1 As New OleDb.OleDbCommand()
With cmd1
.Connection = cnn1
.CommandText = STR3
cnn1.Open()
.ExecuteNonQuery()
cnn1.Close()

End With
End Sub
 
B

Brian Henry

use parameters insted of concatenation...

create a command object of type OleDBCommand

then assign each parameter through the user of the parameters collection of
that object... this will fix your problem
 
Top