?
Solved

Dropdownlist and quote problem

Posted on 2009-02-11
5
Medium Priority
?
278 Views
Last Modified: 2013-12-17
Hi, I'm trying to write a select statement in C# based on the value from my dropdownlist.  

I set a breakpoint in my code and the output displays a double quote at the end:

            sqltext      "select nameoffile from FileViewer where category ='US Corrugated Capabilities'"      string

How would I get rid of that double quote and replace it with a single quote?

string sqltext = "select nameoffile from FileViewer where category =" + "'" + GroupDDL.SelectedItem.Text + "'";

Open in new window

0
Comment
Question by:JeffEae
  • 2
  • 2
5 Comments
 
LVL 9

Expert Comment

by:RobertNZana
ID: 23615436
0
 
LVL 9

Accepted Solution

by:
RobertNZana earned 1500 total points
ID: 23615469
sqltext = sqltext.Replace("""", "'");

0
 

Author Comment

by:JeffEae
ID: 23615513
I tried doing that and I'm still getting the double quote at the end


 string sqltext = "select nameoffile from FileViewer where category =" + "'" + GroupDDL.SelectedItem.Text.Replace("'","''");

Open in new window

0
 

Author Comment

by:JeffEae
ID: 23616851
Finally figured it out, I didn't need to replace the double quote, just had to add an escape character to add a single quote in
string sqltext = "select nameoffile from FileViewer where category =" + "'" + GroupDDL.SelectedItem.Text + "\'";

Open in new window

0
 
LVL 7

Expert Comment

by:keustermans
ID: 23619604
I hope you realize that you are leaving yourself open to sql injection with the way that construct your sql.
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Screencast - Getting to Know the Pipeline
Suggested Courses

840 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