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. How to insert ' into database?

How to insert ' into database?

Scheduled Pinned Locked Moved Database
databasequestiontutorial
10 Posts 6 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.
  • T Offline
    T Offline
    ting668
    wrote on last edited by
    #1

    as title. What is the sql statement? thanks

    S S 2 Replies Last reply
    0
    • T ting668

      as title. What is the sql statement? thanks

      S Offline
      S Offline
      Sudee
      wrote on last edited by
      #2

      http://www.w3schools.com/sql/sql\_select.asp ====== You need a head to program. Cool, fast and sharp.

      T 1 Reply Last reply
      0
      • S Sudee

        http://www.w3schools.com/sql/sql\_select.asp ====== You need a head to program. Cool, fast and sharp.

        T Offline
        T Offline
        ting668
        wrote on last edited by
        #3

        A good link However, i would like to know how to insert char(') into database? e.g Insert into table1 values (''','hhhh') it causes exception THanks

        S 1 Reply Last reply
        0
        • T ting668

          A good link However, i would like to know how to insert char(') into database? e.g Insert into table1 values (''','hhhh') it causes exception THanks

          S Offline
          S Offline
          Sudee
          wrote on last edited by
          #4

          this.SqlConnection = new System.Data.SqlClient.SqlConnection(); cmd = new SqlCommand("INSERT INTO TableName (intColumnA, chrColumnB) VALUES (1,'XYX')",this.SqlConnection); cmd.ExecuteNonQuery(); What exception did you get? ====== Yo need a brain to code.

          T 1 Reply Last reply
          0
          • S Sudee

            this.SqlConnection = new System.Data.SqlClient.SqlConnection(); cmd = new SqlCommand("INSERT INTO TableName (intColumnA, chrColumnB) VALUES (1,'XYX')",this.SqlConnection); cmd.ExecuteNonQuery(); What exception did you get? ====== Yo need a brain to code.

            T Offline
            T Offline
            ting668
            wrote on last edited by
            #5

            sorry I would know to how to insert the character "'" (single quotation character) into the database varchar field. Thanks!

            C E 2 Replies Last reply
            0
            • T ting668

              sorry I would know to how to insert the character "'" (single quotation character) into the database varchar field. Thanks!

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

              Use 4 apostrophes, one for open string, two for the apostrophe and one for the close string. If the apostrophe exists in the middle of a string do something like this: 'doesn''t' Does this help?


              "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!

              I 1 Reply Last reply
              0
              • C Colin Angus Mackay

                Use 4 apostrophes, one for open string, two for the apostrophe and one for the close string. If the apostrophe exists in the middle of a string do something like this: 'doesn''t' Does this help?


                "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!

                I Offline
                I Offline
                iamalik
                wrote on last edited by
                #7

                There is way that you can store ' Find and Replace ' by • (Alt+7) and Insert the string in the database. On Retrival Find and Replace • by ' If you using ASP.Net or VB.Net or C# then Finding and Replacing is no Problem Just Try String.Replace("'","•");P

                1 Reply Last reply
                0
                • T ting668

                  sorry I would know to how to insert the character "'" (single quotation character) into the database varchar field. Thanks!

                  E Offline
                  E Offline
                  EdbertP
                  wrote on last edited by
                  #8

                  Just create a function that replaces all your ' (single apostrophe) with '' (TWO single apostrophe), i.e. [Joe O'Connell] becomes [Joe O''Connell] However, I do recommend using Data Adapters and SQLCommands to pass your parameters so you don't need to worry about this anymore. It does make my life easier aside from being safer from SQL injection.

                  T 1 Reply Last reply
                  0
                  • E EdbertP

                    Just create a function that replaces all your ' (single apostrophe) with '' (TWO single apostrophe), i.e. [Joe O'Connell] becomes [Joe O''Connell] However, I do recommend using Data Adapters and SQLCommands to pass your parameters so you don't need to worry about this anymore. It does make my life easier aside from being safer from SQL injection.

                    T Offline
                    T Offline
                    ting668
                    wrote on last edited by
                    #9

                    Data Adapters and SQLCommands What's that? How to do them? Thanks!;P

                    1 Reply Last reply
                    0
                    • T ting668

                      as title. What is the sql statement? thanks

                      S Offline
                      S Offline
                      Salil Khedkar
                      wrote on last edited by
                      #10

                      Insert into table1 values ('''','hhhh') i.e. replace ' by '' (quote by quote quote)

                      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