Solved

ASP Unclosed quotes error message

Posted on 2007-03-27
3
210 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 37

Expert Comment

by:samtran0331
ID: 18802148
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
ID: 18802165
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
ID: 18802357
samtran0331
  This does get executed in a stored procedure.  But thanks for the info and the link
Points being awarded now
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

730 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