troubleshooting Question

Single Quotes in SqlDataSource Controls?????

Avatar of SamJolly
SamJollyFlag for United Kingdom of Great Britain and Northern Ireland asked on
.NET ProgrammingASP.NET
9 Comments3 Solutions861 ViewsLast Modified:

I have got some "IN ('String1','String') code for a  WHERE clause for some SQL. Unfortunately the quotes are not been brought across correctly so the SQL is failing. See attached code.

I need the correct format for the SqlParameter Default Value property which I guess means escaping the Single Quote characters.

I have tried:

a) 2x Single Quotes
b) using '
c) /'

Nothing works.... If I type the 'String1','String' directly into the SQL text it works fine. However if I put this as a property value or in code then it fails.

Any help greatly appreciated,


<asp:SqlDataSource ID="_sds" runat="server" 
    ConnectionString="<%$ MyConnectionString %>" 
    SelectCommand="SELECT [ID], [Tag], [Description] FROM [Table] WHERE ([Tag] IN (@Tag))">
        <asp:Parameter Name="Tag" Type="String" DefaultValue="'String1','String2'" />
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 3 Answers and 9 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 3 Answers and 9 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros