I'm not quite sure if I understand the problem. The insert statement should work even if the string contains a single quote. However, if you are creating and executing the Insert statement, you'll need to replace the single quotye with two single quotes. and enclose the string in quotes.
Terry and Chip Thanks for your response.
I could solve the problem.
The user enters the data through html form. I insert the data into the database through "insert" statment in my asp file. I wrote a function "replacequote" which replaces a single quote by double quotes in the string and use the new string into "insert" statement.
Ex: "message" is a form field.
message=replacequote(message)
sqltrack = "Insert into users (message)"
sqltrack = sqltrack & "values ('" & message & "')"
Set dbConn = GetConnection()
'Execute the SQL's
dbConn.Execute sqltrack
So if message="It's a test"
replacequote(message) will make message as "It''s a test"
Then it takes care of quotes within the data, and doesn't give SQL server error message "Incorrect syntax near 's".
Now it stores it properly in the database as: It's a test
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.