473,394 Members | 1,759 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

string with quotes

How do I resolve the problem of passing a string that has quotes
within in a SQL statement? Sometimes the string contains a single
quote (') and some others it contains the double quote (")?

Any clue...

Thank you,

Stefania
Nov 13 '05 #1
3 3144
Depends on how you're delimiting the string in your SQL statement.

If you're using a single quote to delimit, you need to change all
occurrences of single quotes in the string to two single quotes in a row:

"... WHERE MyName = '" & Replace(strValue, "'", "''") & "'"

Exagerated for clarity:

"... WHERE MyName = ' " & Replace(strValue, " ' ", " ' ' ") & " ' "

On the other hand, if you're using a double quote to delimit, you need to
change all occurrences of double quotes to two double quotes in a row:

"... WHERE MyName = " & Chr$(34) & Replace(strValue, Chr$(34), Chr$(34) &
Chr$(34)) & Chr$(34)

(In case you weren't aware, Chr$(34) is the same as ")

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)
"Stefania Scott" <st******@u.arizona.edu> wrote in message
news:3e**************************@posting.google.c om...
How do I resolve the problem of passing a string that has quotes
within in a SQL statement? Sometimes the string contains a single
quote (') and some others it contains the double quote (")?

Any clue...

Thank you,

Stefania

Nov 13 '05 #2
Doug,
Thank you for your reply.
My problem is that I cannot change the quotes within the string because
they have a meaning. Infact the string is the translation of a number to
be transformed in a barcode (code 128). So, maybe the solution is that I
need to search the string and if the string contains a double quote use
the single quote and viceversa. However, the problem rise if the string
contains both quotes and in this case I am lost.

Thanks again,

stefania

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 13 '05 #3
If you double your single quotes in your SQL statement, it in fact insert
only one single quote in the DB. The doubled single quote only means "don't
stop the string here and replace these doubled single quotes by only one
before processing the SQL statement" instead of "double this single quote
and insert them in order to my data to be correct". Not sure I'm very clear!
When retreiving your data, there will be only one single quote in it. HTH.

Yannick

"stefania" <st******@italy.it> wrote in message
news:40***********************@news.usenetmonster. com...
Doug,
Thank you for your reply.
My problem is that I cannot change the quotes within the string because
they have a meaning. Infact the string is the translation of a number to
be transformed in a barcode (code 128). So, maybe the solution is that I
need to search the string and if the string contains a double quote use
the single quote and viceversa. However, the problem rise if the string
contains both quotes and in this case I am lost.

Thanks again,

stefania

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 13 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Bengt Richter | last post by:
Why wouldn't quote-stuffing solve the problem, and let you treat \ as an ordinary character? In a raw string, it's no good for preventing end-of-quoting anyway, unless you want the literal \ in...
9
by: PaulThomas | last post by:
I want to "look" through a comma delimited String and "take it apart" by finding the comma's and then put each "set of characters" into seperate strings - - - maybe an array, maybe seperate cells...
5
by: Ann Marinas | last post by:
Happy New Year to all! :D I am currently developoing an application that imports data from a CSV file. Each comma represents an array item that I need to extract data with. My problem is...
6
by: Senthil | last post by:
Code ---------------------- string Line = "\"A\",\"B\",\"C\",\"D\""; string Line2 = Line.Replace("\",\"","\"\",\"\""); string CSVColumns = Line2.Split("\",\"".ToCharArray());
12
by: Jeff S | last post by:
In a VB.NET code behind module, I build a string for a link that points to a JavaScript function. The two lines of code below show what is relevant. PopupLink = "javascript:PopUpWindow(" &...
1
by: Mark Rae | last post by:
Hi folks, Apologies - am having a bit of a "senior moment"... Is there a way to convert a string containing escaped characters into a verbatim string literal? I.e. converting something like...
16
by: Charles Law | last post by:
I have a string similar to the following: " MyString 40 "Hello world" all " It contains white space that may be spaces or tabs, or a combination, and I want to produce an array...
4
by: vighnesh | last post by:
Hello EveryOne In my project I have to parse a string in Quotes as without Quotes.I tried the following code but it didn't work to me. I again getting the string with Quotes, Can Anybody suggest...
9
by: a | last post by:
I need to write a regular expression to match a quoted string in which the double quote character itself is represented by 2 double quotes. For example: "beginning ""nested quoted string"" end"...
4
by: Michael Yanowitz | last post by:
Hello: If I have a long string (such as a Python file). I search for a sub-string in that string and find it. Is there a way to determine if that found sub-string is inside single-quotes or...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.