Click to See Complete Forum and Search --> : Error while inserting Single Quote in TextBox
TheLastBurden
08-14-2006, 06:01 AM
Have created an ASP Help Desk Application . User enters the complaint in the textarea and later inserted into the database.
problem is : if the user enters a word containing a single quote ex. " can't " in the textarea , treating it as a comment, an error is generated.
how can i go about this ?
v_Desc = " Request Dated : " & Now() & "\n" & v_Desc
ahk2chan
08-14-2006, 07:51 AM
I think it is because when you construct the insert SQL, it doens't like the single quote in the string. The easiest way I can think of is to use Server.urlencode to encode the string first, and then do the insert. You need to do the same encode when you want to do search.
You can also create your own function to properly encode the SQL... when you do the insert.
TheLastBurden
08-15-2006, 12:34 AM
thanks...i tried it..but then during display ... it doesn't retrieve single qoute but the encrypted value from database...am still trying ...lemme know if u find a solution...
ahk2chan
08-15-2006, 10:10 AM
Yes, it will insert into the database as the encoded value. Then when you displayed it, you want to use the Server.decode method to decode it.
TheLastBurden
08-16-2006, 12:31 AM
i got it... i just search the search for occurence of sigle quote and replace it with "`" ..cheesy but works ! thanks anyway
russell
08-16-2006, 09:58 AM
no.
escape single quotes by doubling them up (2 single quotes)
Replace(string_value, "'", "''")
TheLastBurden
08-21-2006, 12:49 AM
great..it works...Thanx