Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP General > Double apostrophes

Reply
Thread Tools

Double apostrophes

 
 
Joey Martin
Guest
Posts: n/a
 
      07-13-2005
I'm sure this has to be a simple fix. I just cannot figure it out.

To resolve the typical apostrope issue, I have the
acarriername = Replace(txtcarriername.text, "'", "''")

My problem is that 2 apostrophes are now inserted, instead of one. For
example if someone types in IT'S NICE, when it is displayed in the input
text box later (to allow a user to change it), it says IT''S NICE.

This is a sql 2000 database.

Thanks for the help.




*** Sent via Developersdex http://www.developersdex.com ***
 
Reply With Quote
 
 
 
 
Aaron Bertrand [SQL Server MVP]
Guest
Posts: n/a
 
      07-13-2005
How are you inserting the data into the database? If you are using a
command object and passing the values into a parameter, you don't need to do
the replace since it is handled for you by the provider.

Can you show all of your code so we don't have to guess and grasp at straws?




"Joey Martin" <> wrote in message
news:%...
> I'm sure this has to be a simple fix. I just cannot figure it out.
>
> To resolve the typical apostrope issue, I have the
> acarriername = Replace(txtcarriername.text, "'", "''")
>
> My problem is that 2 apostrophes are now inserted, instead of one. For
> example if someone types in IT'S NICE, when it is displayed in the input
> text box later (to allow a user to change it), it says IT''S NICE.
>
> This is a sql 2000 database.
>
> Thanks for the help.
>
>
>
>
> *** Sent via Developersdex http://www.developersdex.com ***



 
Reply With Quote
 
 
 
 
Bob Barrows [MVP]
Guest
Posts: n/a
 
      07-13-2005
Joey Martin wrote:
> I'm sure this has to be a simple fix. I just cannot figure it out.
>
> To resolve the typical apostrope issue, I have the
> acarriername = Replace(txtcarriername.text, "'", "''")
>
> My problem is that 2 apostrophes are now inserted, instead of one. For
> example if someone types in IT'S NICE, when it is displayed in the
> input text box later (to allow a user to change it), it says IT''S
> NICE.
>

Only do the replace when writing the data into the database. Do not do it
any other time.

Better yet, stop using dynamic sql. The only reason you have to escape the
apostrophe is because you are not using parameters. See these:

http://groups.google.com/groups?hl=e...tngp13.phx.gbl
http://groups-beta.google.com/group/...e36562fee7804e
http://tinyurl.com/jyy0

If this does not answer your question, post a short repro script so we can
see what you're doing.

HTH,
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.


 
Reply With Quote
 
Joey Martin
Guest
Posts: n/a
 
      07-13-2005

Current code:

Set RS = Server.CreateObject("ADODB.Recordset")
sqlUpdate = "SELECT * FROM ricprops WHERE propno='" & Request("id") &
"'"

RS.open sqlUpdate,Conn,1,3
RS("comments") = Replace(Request.form("comments"), "'", "''")
RS.Update
RS.Close




*** Sent via Developersdex http://www.developersdex.com ***
 
Reply With Quote
 
Aaron Bertrand [SQL Server MVP]
Guest
Posts: n/a
 
      07-13-2005
Ugh. How about:

comments = replace(request.form("comments"), "'", "''")
id = replace(request.form("id"), "'", "''")
sql = "UPDATE ricprops SET comments = '" & comments & "' WHERE propno='" &
id & "'"
conn.execute sql,,129

Or see Bob's link.

Note you should use request.form() not the lazy request().

Also, why is the column propno a character datatype? Terrible name--no
implies number.


 
Reply With Quote
 
Joey Martin
Guest
Posts: n/a
 
      07-13-2005
Bob,
Not sure I understand your comments about not using dynamic sql. I read
the documents and it seems as if I do it the correct way. USUALLY, I do
not use a recordset to update variables. My current code does, because
it's old code and I never re-wrote it. Usually, I do the following:

if request("submit")<> "" then
v1=Replace(Request.form("v1"), "'", "''")
v2=Replace(Request.form("v2"), "'", "''")

sql="update table set v1='" & v1 & "',v2='" & v2 & "' where id='1'"
conn.execute (sql)



Is that incorrect? Doing it this way, I still get the double apostrophe.




*** Sent via Developersdex http://www.developersdex.com ***
 
Reply With Quote
 
Joey Martin
Guest
Posts: n/a
 
      07-13-2005

Aaron,

What made you think propno is a CHAR datatype? It is INT.
The way you wrote the code is how I USUALLY do it.
But, doing it that way,as you wrote, I still receive double apostrophes.

THANKS!!


*** Sent via Developersdex http://www.developersdex.com ***
 
Reply With Quote
 
Aaron Bertrand [SQL Server MVP]
Guest
Posts: n/a
 
      07-13-2005
> sql="update table set v1='" & v1 & "',v2='" & v2 & "' where id='1'"
> conn.execute (sql)
>
>
>
> Is that incorrect? Doing it this way, I still get the double apostrophe.


Then you are also doing the replace when you DISPLAY the data, which you
shouldn't be doing.


 
Reply With Quote
 
Aaron Bertrand [SQL Server MVP]
Guest
Posts: n/a
 
      07-13-2005
> What made you think propno is a CHAR datatype? It is INT.

Because in your query, you surround it with quotes:

> WHERE propno='" & Request("id") & "'"


If it's an INT, don't do that!

A


 
Reply With Quote
 
Joey Martin
Guest
Posts: n/a
 
      07-13-2005
Aaron,

When displaying the data in my textarea box, here is the code:
<textarea cols="30" rows="10"
name="comments"><%=trim(rs("comments"))%></textarea>


At that time, it displays IT''S NICE.





*** Sent via Developersdex http://www.developersdex.com ***
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
URLEncode doesn't like apostrophes? darrel ASP .Net 0 07-08-2005 08:05 PM
HtmlEncode with apostrophes Andy Fish ASP .Net 4 04-06-2005 03:28 PM
Replacing apostrophes for an sql statements MS Java 3 02-22-2005 10:49 AM
cannot convert parameter from 'double (double)' to 'double (__cdecl *)(double)' error Sydex C++ 12 02-17-2005 06:30 PM
SQL and apostrophes Chris Huddle ASP .Net 2 12-10-2003 07:36 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57