none
Replace single quotes in select command RRS feed

  • Question

  • Hi,

    This is driving me crazy.  I have a database field in which I need to replace single quotes (i.e. ') with a blank string so that it will cease throwing off my sql query built at run-time.  I think this is a pretty common problem but I can never get it right. Your help is greatly appreciated. The below is wrong.  Can someone show me how to make it right?  Thank you.

     
     SqlCommand com = new SqlCommand("select empid, replace(mname," + "'" + ", " + "''" + ") from empmast", empmastcon);                          
    

    Tuesday, September 30, 2014 8:01 PM

Answers

  • replace(mname,'''','')

    This works without doing anything special.  I must need a vacation.

    • Marked as answer by fralo Tuesday, September 30, 2014 8:45 PM
    Tuesday, September 30, 2014 8:45 PM

All replies

  • replace(mname,'''','')

    This works without doing anything special.  I must need a vacation.

    • Marked as answer by fralo Tuesday, September 30, 2014 8:45 PM
    Tuesday, September 30, 2014 8:45 PM
  • replace(mname,'''','')

    This works without doing anything special.  I must need a vacation.

    Hi fralo,

    Thank you for sharing your solution here:)


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, October 3, 2014 7:43 AM