473,396 Members | 2,052 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,396 software developers and data experts.

quote delimiters double and single

I am attempting to build a command string to update a field in a dataset.
the command string looks like this:
Dim cmdString As String = "Update [data table] set lName = '" & clName.Trim
& "', fName = '" & cfName.Trim & "' Where id = " & lnID

the command works fine unless and until clname and/or cfname contains an
apostrophe, ie: O'Hare

When the executeNonquery is run, the quotes are out of balance and a syntax
error is thrown.

How can I build a command to update a field where it has apostrophes? I
can't find any way to change delimiters, like using brackets around the
variables [O'Hare] instead of a single tick.

thanx.

daver
Jul 21 '05 #1
2 1449
David Bird <co**********@hotmail.com> wrote:
I am attempting to build a command string to update a field in a dataset.
the command string looks like this:
Dim cmdString As String = "Update [data table] set lName = '" & clName.Trim
& "', fName = '" & cfName.Trim & "' Where id = " & lnID

the command works fine unless and until clname and/or cfname contains an
apostrophe, ie: O'Hare

When the executeNonquery is run, the quotes are out of balance and a syntax
error is thrown.

How can I build a command to update a field where it has apostrophes? I
can't find any way to change delimiters, like using brackets around the
variables [O'Hare] instead of a single tick.


The best thing is not to build up your command string like that in the
first place. Instead, use parameterised SQL. That way you don't need to
do any quoting yourself.

See http://www.pobox.com/~skeet/csharp/faq/#db.parameters

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #2
Are you using sql server? If you so, you'll need to escape the apostrophe
with yet another apostrophe:

Dim cmdString As String = _
"Update [data table] set lName = '" & _
Replace(clName.Trim, "'", "''") & "', _
fName = '" & Replace(cfName.Trim, "'", "''") & _
"' Where id = " & lnID

I believe its the same for Access but I'm not sure about other databases.

hope that helps..
Imran.
I am attempting to build a command string to update a field in a
dataset.
the command string looks like this:
Dim cmdString As String = "Update [data table] set lName = '" &
clName.Trim
& "', fName = '" & cfName.Trim & "' Where id = " & lnID
the command works fine unless and until clname and/or cfname contains
an apostrophe, ie: O'Hare

When the executeNonquery is run, the quotes are out of balance and a
syntax error is thrown.

How can I build a command to update a field where it has apostrophes?
I can't find any way to change delimiters, like using brackets around
the variables [O'Hare] instead of a single tick.

thanx.

daver


Jul 21 '05 #3

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

Similar topics

12
by: Joshua Beall | last post by:
Hi All, I have heard other people say that PHP can parse double quoted strings (e.g., "Hello, World") faster than it can parse single quoted strings (e.g., 'Hello, World'). This seems backwards...
2
by: Simon Bunker | last post by:
I was just wondering why python doesn't make a distinction between single and double quotes - a bit like Perl does. Obviously I realise there are no dollar signs so you can't intrpolate a...
10
by: John | last post by:
Ok, I posted in here a few days ago about a problem with apostrophes in text fields and I tried a few of the suggestions and now I'm in so deep I looking at scraping the whole thing because now I...
8
by: Steve | last post by:
How do I get a single quote (') in a NVARCHAR string in MS SQL Server? e.g. SELECT @strsql = "SELECT * FROM tblTest WHERE Field1 Like 'blah'' Obviously this is invalid as the single quote...
3
by: dps027 | last post by:
Hi all - I wonder if there is any way to specify in UDB for Windows version 7 so that in the DEL Export file, there is no double quote (i.e. ") nor any character strings surrounding the columns of...
2
by: David Bird | last post by:
I am attempting to build a command string to update a field in a dataset. the command string looks like this: Dim cmdString As String = "Update set lName = '" & clName.Trim & "', fName = '" &...
4
by: Jack | last post by:
Hi, I have a asp page where part of the code is as follows. This builds up the sql statement partially. sql01 = "UPDATE EquipmentTbl SET " sql01 = sql01 & "SerialNumber = '" &...
3
by: Eric Layman | last post by:
Hi, I've saved data into the db by doing a replace() on single quote. Right now on data display on a datagrid, it shows double single quote. How do I make changes during run time of datagrid...
4
by: wxPythoner | last post by:
There's a thing that bugs me in Python. Look at this... SyntaxError: EOL while scanning single-quoted string Please focus on the part of the error message that states "while scanning...
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
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.