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. Database & SysAdmin
  3. Database
  4. Store " ' " in database

Store " ' " in database

Scheduled Pinned Locked Moved Database
databasesql-servervisual-studiosysadminquestion
8 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.
  • I Offline
    I Offline
    imshally81
    wrote on last edited by
    #1

    Hi All, I wanna store " ' " in data base ....for e.g, "father's" or "isn't", i m using VS 2003 with SQL Server 2000.. so how can i achive this task Thanx Sajjad

    A D C 3 Replies Last reply
    0
    • I imshally81

      Hi All, I wanna store " ' " in data base ....for e.g, "father's" or "isn't", i m using VS 2003 with SQL Server 2000.. so how can i achive this task Thanx Sajjad

      A Offline
      A Offline
      Andy Brummer
      wrote on last edited by
      #2

      Use an ADO.Net parameter to pass the data in rather then building the SQL dynamically. If you have to build dyanmic sql, '' gets translated to ', so 'father''s' is stored as father's. This is typically done with a call to Replace("'", "''")

      I 1 Reply Last reply
      0
      • I imshally81

        Hi All, I wanna store " ' " in data base ....for e.g, "father's" or "isn't", i m using VS 2003 with SQL Server 2000.. so how can i achive this task Thanx Sajjad

        D Offline
        D Offline
        DiWa
        wrote on last edited by
        #3

        insert into values ('''') will insert a single "'" "fathers'''s" or "isn'''t" will do.... dirk

        I 1 Reply Last reply
        0
        • A Andy Brummer

          Use an ADO.Net parameter to pass the data in rather then building the SQL dynamically. If you have to build dyanmic sql, '' gets translated to ', so 'father''s' is stored as father's. This is typically done with a call to Replace("'", "''")

          I Offline
          I Offline
          imshally81
          wrote on last edited by
          #4

          thanx for reply... but i wanna store in database ' father's ' not ' father"s ' i think u understand my point.. thanx

          A 1 Reply Last reply
          0
          • D DiWa

            insert into values ('''') will insert a single "'" "fathers'''s" or "isn'''t" will do.... dirk

            I Offline
            I Offline
            imshally81
            wrote on last edited by
            #5

            Thanx for reply... u means if i wanna insert " father's " in data base so we enter text as " father'''s " am i write ..? basically i used VS 2003(ASP.NET with VB.NET) with SQL Server 2000,so if u have any sample code for this... i shall very thankfull of u...

            D 1 Reply Last reply
            0
            • I imshally81

              thanx for reply... but i wanna store in database ' father's ' not ' father"s ' i think u understand my point.. thanx

              A Offline
              A Offline
              Andy Brummer
              wrote on last edited by
              #6

              imshally81 wrote: but i wanna store in database ' father's ' not ' father"s ' That's what I told you how to do. '' is a string escape code for ' in sql just like \t for tab in C or "" for " in VB.


              I can imagine the sinking feeling one would have after ordering my book, only to find a laughably ridiculous theory with demented logic once the book arrives - Mark McCutcheon

              1 Reply Last reply
              0
              • I imshally81

                Thanx for reply... u means if i wanna insert " father's " in data base so we enter text as " father'''s " am i write ..? basically i used VS 2003(ASP.NET with VB.NET) with SQL Server 2000,so if u have any sample code for this... i shall very thankfull of u...

                D Offline
                D Offline
                DiWa
                wrote on last edited by
                #7

                Yup, at least that is Standard-SQL, should work with most Databases, for shure with SQL Server and Oracle. You could try it out from Enterprise Manager or Query Analyser by raising a INSERT statement from there.

                1 Reply Last reply
                0
                • I imshally81

                  Hi All, I wanna store " ' " in data base ....for e.g, "father's" or "isn't", i m using VS 2003 with SQL Server 2000.. so how can i achive this task Thanx Sajjad

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

                  Use a parameterised query to store the information, they it will permit you to put in the apostrophe character. I have a blog entry (http://blogs.wdevs.com/colinangusmackay/archive/2004/09/25/652.aspx[^])that shows going from injecting values in SQL to using a parameterised query to do the same thing. You will find that if you do that you don't have to worry about the apostrophes any more because the framework will handle that for you. You should also take care in your code so you don't expose it to the possibility of SQL Injection Attacks. The symptoms of the problem you currently describe show that your code is vulnerable to attack and should be corrected. I also wrote an article about that (SQL Injection Attacks and Tips on How to Prevent Them[^]) Does this help?


                  My: Blog | Photos WDevs.com - Open Source Code Hosting, Blogs, FTP, Mail and More

                  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