Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Escape Single Quote

Escape Single Quote

Scheduled Pinned Locked Moved C#
databasealgorithmsquestion
5 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    cjengler
    wrote on last edited by
    #1

    Hi, Is there a simple method to place two single quotes anywhere there is a single quote so that single quotes can be inserted into a database? Currently I have been searching through each string (textbox, or what ever it may be) and manually (looking at each character in the string) replacing the single quote with two single quotes. I have also tried the Replace function but that does not appear to change the single quotes. If any one has experinced this please pass on your knowledge or point me in the right direction. Thanks Joe

    C B 2 Replies Last reply
    0
    • C cjengler

      Hi, Is there a simple method to place two single quotes anywhere there is a single quote so that single quotes can be inserted into a database? Currently I have been searching through each string (textbox, or what ever it may be) and manually (looking at each character in the string) replacing the single quote with two single quotes. I have also tried the Replace function but that does not appear to change the single quotes. If any one has experinced this please pass on your knowledge or point me in the right direction. Thanks Joe

      C Offline
      C Offline
      Colin Angus Mackay
      wrote on last edited by
      #2

      If you use parametarised queries you can get around this problem. Also, parameterised queries are more secure as they are less suseptable to injection attacks.


      "If a man empties his purse into his head, no man can take it away from him, for an investment in knowledge pays the best interest." -- Joseph E. O'Donnell Not getting the response you want from a question asked in an online forum: How to Ask Questions the Smart Way!

      H 1 Reply Last reply
      0
      • C cjengler

        Hi, Is there a simple method to place two single quotes anywhere there is a single quote so that single quotes can be inserted into a database? Currently I have been searching through each string (textbox, or what ever it may be) and manually (looking at each character in the string) replacing the single quote with two single quotes. I have also tried the Replace function but that does not appear to change the single quotes. If any one has experinced this please pass on your knowledge or point me in the right direction. Thanks Joe

        B Offline
        B Offline
        Brad Bruce
        wrote on last edited by
        #3

        I use replace() for this all the time... Replace("'", "''")

        1 Reply Last reply
        0
        • C Colin Angus Mackay

          If you use parametarised queries you can get around this problem. Also, parameterised queries are more secure as they are less suseptable to injection attacks.


          "If a man empties his purse into his head, no man can take it away from him, for an investment in knowledge pays the best interest." -- Joseph E. O'Donnell Not getting the response you want from a question asked in an online forum: How to Ask Questions the Smart Way!

          H Offline
          H Offline
          Hugo Hallman
          wrote on last edited by
          #4

          And they are much faster too, since the SQL (which has to be compiled) can be cached for every request. There's simply no excuse for not using them!:)

          C 1 Reply Last reply
          0
          • H Hugo Hallman

            And they are much faster too, since the SQL (which has to be compiled) can be cached for every request. There's simply no excuse for not using them!:)

            C Offline
            C Offline
            Colin Angus Mackay
            wrote on last edited by
            #5

            Hugo Hallman wrote: they are much faster too Good point! I keep forgetting that. I still have this mind set that you have to make a stored procedure for to have the SQL cached in a pre-compiled state.


            "If a man empties his purse into his head, no man can take it away from him, for an investment in knowledge pays the best interest." -- Joseph E. O'Donnell Not getting the response you want from a question asked in an online forum: How to Ask Questions the Smart Way!

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups