Dropdownlist and quote problem

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

JeffEaeAsked:
Who is Participating?
 
RobertNZanaCommented:
sqltext = sqltext.Replace("""", "'");

0
 
RobertNZanaCommented:
0
 
JeffEaeAuthor Commented:
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
 
JeffEaeAuthor Commented:
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
 
keustermansCommented:
I hope you realize that you are leaving yourself open to sql injection with the way that construct your sql.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.