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. Visual Basic
  4. SQL query problem

SQL query problem

Scheduled Pinned Locked Moved Visual Basic
databasequestionhelpannouncement
7 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.
  • S Offline
    S Offline
    sunil goyalG
    wrote on last edited by
    #1

    hi all, i run a query which update a field , is failed when it contains single or double quote.Otherwise it is running successfully. sample query is following update table1 set name='abcd'efg' please suggest how can i solve this problem ?

    N R D B 4 Replies Last reply
    0
    • S sunil goyalG

      hi all, i run a query which update a field , is failed when it contains single or double quote.Otherwise it is running successfully. sample query is following update table1 set name='abcd'efg' please suggest how can i solve this problem ?

      N Offline
      N Offline
      nishkarsh_k
      wrote on last edited by
      #2

      sunil goyalG wrote:

      update table1 set name='abcd'efg'

      try this update table1 set name='abcd\'efg' ' and \ are excape characters so one has to put "\" before them to send as proper query

      S N 2 Replies Last reply
      0
      • S sunil goyalG

        hi all, i run a query which update a field , is failed when it contains single or double quote.Otherwise it is running successfully. sample query is following update table1 set name='abcd'efg' please suggest how can i solve this problem ?

        R Offline
        R Offline
        Rajesh Anuhya
        wrote on last edited by
        #3

        Perfect Query update table1 set name='abcd''efg'

        Rajesh B --> A Poor Workman Blames His Tools <--

        1 Reply Last reply
        0
        • N nishkarsh_k

          sunil goyalG wrote:

          update table1 set name='abcd'efg'

          try this update table1 set name='abcd\'efg' ' and \ are excape characters so one has to put "\" before them to send as proper query

          S Offline
          S Offline
          sunil goyalG
          wrote on last edited by
          #4

          This solution is not works for me. query is failed. I am using SQL Server Express 2005

          1 Reply Last reply
          0
          • S sunil goyalG

            hi all, i run a query which update a field , is failed when it contains single or double quote.Otherwise it is running successfully. sample query is following update table1 set name='abcd'efg' please suggest how can i solve this problem ?

            D Offline
            D Offline
            Dave Kreskowiak
            wrote on last edited by
            #5

            THe problem is that you are using string concantenation (newString = "SomeString" & "SomeOtherString") to build your SQL statement. Don't. Use parameterized queries instead and this problem is solved for you. Read this[^] article for why you should not be doing what you're doing and how to use parameters.

            A guide to posting questions on CodeProject[^]
            Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                 2006, 2007, 2008

            1 Reply Last reply
            0
            • S sunil goyalG

              hi all, i run a query which update a field , is failed when it contains single or double quote.Otherwise it is running successfully. sample query is following update table1 set name='abcd'efg' please suggest how can i solve this problem ?

              B Offline
              B Offline
              bigsagal
              wrote on last edited by
              #6

              Any time you are updating a column which may contain a single quote, you must scan and replace the single quote with two single quotes. If your column contains 5 single quotes, your column will contain 10 single quotes after the scan and replace. During the update, two successive single quotes will be converted back to a single quote. For example, if your column contains 'abc'd''ef' before the scan and replace, your column will contain 'abc''d''''ef' after the scan and replace. After the update, your column in the database will contain your original column value namely 'abc'd''ef'.

              bigsagal, confused as all get out!

              1 Reply Last reply
              0
              • N nishkarsh_k

                sunil goyalG wrote:

                update table1 set name='abcd'efg'

                try this update table1 set name='abcd\'efg' ' and \ are excape characters so one has to put "\" before them to send as proper query

                N Offline
                N Offline
                Nanda_MR
                wrote on last edited by
                #7

                use the instant of ' Asc char. It will work i also tried in my system it is working properly . Ananda

                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