Comments are available to members only. Sign up or Log in to view these comments.
Main Topics
Browse All TopicsMy OS is Windows XP SP2 and my IDE is Visual Studio 2005. My program is written in VB.NET 2005. My RDBMS is MySQL version 5.0.45
Context: I have been working on this program for about 2 years now so I have lots of experience writing dynamic SQL that successfully interfaces with MySQL. The commented out code
'Return Chr(39) & Input.Replace("'"c, "\'") & Chr(39)
was written about one year 5 months ago and was working just fine in VB.NET 2003. I upgraded to VB.NET 2005 last January and have not rigerously tested this function, FixSingleQuote1, since then. It just seemed to work when I used it till today when I happen to stress it a little harder. The commented line of code was provided to me by another EE Expert and was the only line of code in the whole function till today. He said it used Regular Expression syntax which I was not familiar with at the time, but I made up some rigorious test cases and it worked without any problems. I took him at his word and I still do. I confess I never really understood how it worked, but since it did, I didn't question it. I just used it and was glad for a freebee that solved a problem for which I had a much less elegent solution that only worked when there was just one single quote in the input text string.
Today I copied and pasted from a webpage some biographical data on one of the US Supreme Court Justices that I was using as test data. It had a few single quotes in it that caused MySQL to return an error message saying my SQL syntax had an error in it. Maybe this was the first time since converting to VB.NET 2005 that I have actually tried to enter any text that had single quotes in it.
I am just trying to convert all occurances of a string of length one from a single quote character to a two character string of backslash single quote and return the whole string delimited by single quote characters, The help gives the following example:
Dim TestString As String = "Shopping List"
' Returns "Shipping List".
Dim aString As String = Replace(TestString, "o", "i")
This looks like a very simple function to use. In debug I can step through the code and see the single quote characters in my Input string. I can execute the assignment statement and look at the Output string. Nothing has changed. The single quotes are still there without the backslash character preceding them. Char(92) = ASCII backslash character and Char(39) is the single quote character.
This is so simple I can't see where I am doing anything wrong. If I am wrong, I'm not too proud to admit it. If this is a known bug in VB.NET 2005, is there a commonly used work around?
Thank you,
Ted Palmer
www.tedpalmer.com
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Business Accounts
Answer for Membership
by: margajet24Posted on 2008-07-08 at 20:59:26ID: 21960502
Comments are available to members only. Sign up or Log in to view these comments.