how to handle single quote character in with sql server queries

Posted on 2008-11-06
Last Modified: 2012-05-05
how to handle single quot character in with sql server queries
Question by:rbadhan
    LVL 3

    Expert Comment

    Please post some more information about what you are trying to do.  If you are getting errors please post an example.  Thanks.
    LVL 1

    Accepted Solution

    Are you having trouble building the query, or handling the user input?

    Your best bet building the query would probably be to use parameterized queries. Stored procedures are best, but even inline sql can use parameters, eg:

    Dim cmd as new SqlCommand("Insert INTO table (name, email) values (@name, @Email)")
    cmd.Parameters.Add("@Name", "me")
    cmd.Parameters.Add("@Email", "")

    Rather than "Insert INTO table (name, email) values ('" & somevar & "', '" & someothervar & "')"

    If the trouble is handling single quotes in user input try encoding the text using Server.HtmlEncode/Server.HtmlDecode...

    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    Join & Write a Comment

    In this article, I will show how to use the Ribbon IDs Tool Window to assign the built-in Office icons to a ribbon button.  This tool will help us to find the OfficeImageId that corresponds to our desired built-in Office icon. The tool is part of…
    Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
    This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA.…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!

    732 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

    23 Experts available now in Live!

    Get 1:1 Help Now