Groups | Blog | Home
all groups > inetserver asp db > august 2004 >

inetserver asp db : Update SET ?


Bob Barrows [MVP]
8/30/2004 3:24:21 PM
[quoted text, click to view]

Assuming you are using dynamic sql (not recommended), use Replace() to
double up the single quote character. Characters are "escaped" by doubling
them up. The escaped characters are automatically converted into the single
literal character when the string is processed.

http://www.aspfaq.com/show.asp?id=2035

This whole issue can be avoided (along with preventing SQL Injection) y
passing data via parameters.

Bob Barrows

--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.

Ray Costanzo [MVP]
8/30/2004 3:24:59 PM
As for the "

This isn't an issue with building your query. It is merely an issue with
building a string. Example:

sVar = "The sign over the door says "Employees Only.""

When this is interpreted by the scripting host, it will see that " before
Employees and take that to mean the end of your string. Then, any
characters that appear after it will just cause confusion, hence an error.
The way to "escape" quotes in VB Script (is that what you're using) is by
doubling them. IE:

sVar = "The sign over the door says ""Employees Only."""

--------------------------------------

As for the '

' is the delimiter used mostly for text in SQL queries. If you have a ' in
your text that you're updating, inserting, or whatever, you need to "escape"
that for the query. This is done by doubling the ' character. So, if you
have this:

sLastname = "O'Brien"

You'd want to essentially do:

sSQL = "select something from somewhere where lastname='" &
Replace(sLastname, "'", "''") & "'"

That would produce a sSQL value of

select something from somewhere where lastname='O''Brien'

---------------------------------------

For more detailed assistance, post your code and your errors when you are
posting about code and errors.

Ray at work






[quoted text, click to view]

TomT
8/30/2004 8:09:56 PM
Taking data from a form, and using UPDATE tablename SET

Seems to be working fine... EXCEPT..

Certain characters cause an error when the update happens.

These include:
' "

' causes an SQL error (Syntax error (missing operator) in query expression)

" data after or between the "" is not displayed..

How do I trap these ? and stop these errors ?

Thanks

AddThis Social Bookmark Button