|
-
Aug 7th, 2000, 01:26 PM
#1
Thread Starter
New Member
I would like to be able to insert a statement into my table which contains a number of single quotes. For ex.,
'John's friend'.
What do I surround this statement with in my SQL to avoid errors?
Thank you,
Olga
-
Aug 7th, 2000, 02:19 PM
#2
Frenzied Member
-
Aug 8th, 2000, 01:01 AM
#3
Excuse me, Gentlemen ....
JHausMann, I just want to clarify...
Do you mean the string should be "John's Friend" ?
Thanks in advance for your reply...
-
Aug 8th, 2000, 11:20 AM
#4
Frenzied Member
-
Aug 8th, 2000, 12:00 PM
#5
I am not sure what version of VB you are using so here is a solution that will work for sure:
Code:
Public Function FixQuotes(A As String)
Dim i As Integer
i = InStr(A, "'")
Do While i > 0
A = Left(A, i) & Mid(A, i)
i = InStr(i + 2, A, "'")
Loop
FixQuotes = A
End Function
Then use it in this fashion:
Code:
YourString = "John's Friend"
YourString = FixQuotes(YourString) ' String now is John''s Friend
Also you could use this function to fix all text boxes on a form:
Code:
Public Sub FixFormQuotes(glCallfrm As Form)
Dim mycontrol As Control
For Each mycontrol In glCallfrm.Controls
If TypeOf mycontrol Is TextBox Then
mycontrol.Text = FixQuotes(mycontrol.Text)
End If
Next
End Sub
If you are using VB6 you could also use the replace function, just replace single quotes with two single quotes.
Hope this helps,
-
Aug 8th, 2000, 12:06 PM
#6
Frenzied Member
It's kind of hard (not impossible, but hard) to wrap a SQL command in single quotes in VB, simply because the compiler will treat it as a comment....
-
Aug 9th, 2000, 08:04 AM
#7
New Member
There may be an even easier way to doing this. If you are using a sybase database try making a stored proceedure in the database and pass your string to it as an argument, it may even speed things up.
"Oh damn why does this not work"
"Every computer is a F.R.E.D, Freeking Ridiculous Electronic Device, the first word depending on your level of frustration"
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|