groone
asked on
VB6 SQL usage myDB.execute help
In an application I have a sql call similar to the one below:
mydb.Execute ("DELETE FROM myTable WHERE myField = '" & Combo1.Text & "'")
Now the problem exist that the myField can contain an apostrophe like in - Gun's - but when this happens the SQL statement bombs. How can I use this statement when such an occurence exists?
mydb.Execute ("DELETE FROM myTable WHERE myField = '" & Combo1.Text & "'")
Now the problem exist that the myField can contain an apostrophe like in - Gun's - but when this happens the SQL statement bombs. How can I use this statement when such an occurence exists?
300 point? :)
mydb.Execute ("DELETE FROM myTable WHERE myField = """ & Combo1.Text & """")
hes i am not agree with you about using another function instead using two " in a text.
regards
suat
mydb.Execute ("DELETE FROM myTable WHERE myField = """ & Combo1.Text & """")
hes i am not agree with you about using another function instead using two " in a text.
regards
suat
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Dim sText as String
sText = Replace(Combo1.Text, "'", "''")
mydb.Execute("DELETE FROM myTable WHERE myField = '" & sText & "''"
The object is to replace any apostrophes within the text with double apostrophes. This will keep SQL from bombing as well as retain the apostrophes within the original text in the DB.
sText = Replace(Combo1.Text, "'", "''")
mydb.Execute("DELETE FROM myTable WHERE myField = '" & sText & "''"
The object is to replace any apostrophes within the text with double apostrophes. This will keep SQL from bombing as well as retain the apostrophes within the original text in the DB.
Thank u
mydb.Execute ("DELETE FROM myTable WHERE myField = '" & Replace(Combo1.Text,"'","'
Because it is hard to read it is replace one ' with two ''