Solved

ASP Unclosed quotes error message

Posted on 2007-03-27
3
203 Views
Last Modified: 2011-10-03
I have an application that people can paste into an input box information from a Word Document.  The data gets posted to a SQL Server database.

However...if the text includes an apostrophe like this line

in one of Boca Raton's finest

Theres an error message.  What can I do to get it to accept the apostrophe?  Error message follows

Incorrect syntax near 's'.
Unclosed quotation mark after the character string ' where txtAdID=4134'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: Incorrect syntax near 's'.
Unclosed quotation mark after the character string ' where txtAdID=4134'.

Source Error:


Line 56:         sSQL = sSQL & " where txtAdID=" & Request.QueryString("txtAdID")
Line 57:         oCom2.CommandText = sSQL
Line 58:         oCom2.ExecuteNonQuery()
Line 59:         oCom2.Dispose()

 
0
Comment
Question by:lrbrister
  • 2
3 Comments
 
LVL 37

Expert Comment

by:samtran0331
Comment Utility
you should always use parameterized queries:
http://aspnet101.com/aspnet101/tutorials.aspx?id=1

doing sql like this:
sSQL = sSQL & " where txtAdID=" & Request.QueryString("txtAdID")

is bad...it leaves you open to sql injection attacks as well as problems like this with the apostrophe
0
 
LVL 37

Accepted Solution

by:
samtran0331 earned 500 total points
Comment Utility
here's another article on parameterized queries:
http://www.4guysfromrolla.com/webtech/092601-1.shtml

also, the first page gives you a "quick fix" for your apostrophe problem...but I'd highly recommend that you use parameterized queries and/or stored procedures
0
 

Author Comment

by:lrbrister
Comment Utility
samtran0331
  This does get executed in a stored procedure.  But thanks for the info and the link
Points being awarded now
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now