Greetings!
I'm using classic ASP and an insert statement to save bulletin messages to a database that can be updated or viewed later. At first I thought it worked perfectly so I took some sample messages and one of them kept erroring out.
I've pretty much determined that it hates the ' character.. and I'm sure it'd hate other special characters as well so here's my question. How do I insert special characters into a database? My co-worker suggested HTMLencode and decode but really that's not going to work.
hi Arielle,
if you are using sql server2000 for backend activities, it accepts all the special characters while inserting a record,except for ' single quotes. You would have noticed that it throws errors, when we try to insert something like this:
eg:
insert into <tablename> values(val1,val2,'the student's of csc dept have scored the highest')
unclosed quotation mark before the character string...
incorrect syntax near...
if you want to insert your message that contains apostophe character from your asp page to sql server table, then you will have to use the Replace() function in your asp page.
Replace(string,find,replacewith)
where,
string: the string to be searched
find: the part of the string that will be replaced
replacewith: the replacement substring
eg: dim txt,crreason
txt=request("txtCrReason")
crreason=Replace(txt,"'","''")
....and send the value stored in the variable 'crreason' to your insert query.
try this and let me know if it has solved your problem. Gud Luck!
cheers,
jai