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. Web Development
  3. ASP.NET
  4. scape sequence in insert query

scape sequence in insert query

Scheduled Pinned Locked Moved ASP.NET
databasehelp
4 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.
  • S Offline
    S Offline
    srinandan
    wrote on last edited by
    #1

    hi all:) i am submitting a query like insert into test(PID,Details)values(2,'"+txtdetails.Text+"') problem with me if the txtdetails contain the string like "amit's bother resides in delhi" the character(') create a problem. i don't want any loop to check the index of the character(') because the string is too large having number of character like('). please just i want a simple query to insert the string. thanks in advance, srinandan

    D E M 3 Replies Last reply
    0
    • S srinandan

      hi all:) i am submitting a query like insert into test(PID,Details)values(2,'"+txtdetails.Text+"') problem with me if the txtdetails contain the string like "amit's bother resides in delhi" the character(') create a problem. i don't want any loop to check the index of the character(') because the string is too large having number of character like('). please just i want a simple query to insert the string. thanks in advance, srinandan

      D Offline
      D Offline
      Deepak the Cool
      wrote on last edited by
      #2

      insert into test(PID,Details)values(2,'"+txtdetails.Text+"') used command parameters int ptd1=2; cmd = new SqlCommand("Insert into test(PTD,Details) values (@ptd,@details1)",connection name) cmd.Parameters.Add("@ptd",ptd) cmd.Parameters.Add("@details1",txtdetails.text.trim()); myconn.Open(); cmd.ExecuteNonQuery(); myconn.Close(); or simple insert 2 and use parameter for second one. anuj

      dcjoshi2

      1 Reply Last reply
      0
      • S srinandan

        hi all:) i am submitting a query like insert into test(PID,Details)values(2,'"+txtdetails.Text+"') problem with me if the txtdetails contain the string like "amit's bother resides in delhi" the character(') create a problem. i don't want any loop to check the index of the character(') because the string is too large having number of character like('). please just i want a simple query to insert the string. thanks in advance, srinandan

        E Offline
        E Offline
        e laj
        wrote on last edited by
        #3

        I don't know a simple way. You should do: string str = "this is a 'sample string'"; str = str.Replace("'", "''"); thats all. Try it! elaj

        1 Reply Last reply
        0
        • S srinandan

          hi all:) i am submitting a query like insert into test(PID,Details)values(2,'"+txtdetails.Text+"') problem with me if the txtdetails contain the string like "amit's bother resides in delhi" the character(') create a problem. i don't want any loop to check the index of the character(') because the string is too large having number of character like('). please just i want a simple query to insert the string. thanks in advance, srinandan

          M Offline
          M Offline
          Member 96
          wrote on last edited by
          #4

          What you are trying to do is incredibly dangerous. You should never insert user submitted text directly into a database in this way because you are opening up your application to a SQL injection attack. See this article for more info: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnpag2/html/PAGHT000002.asp?_r=1[^]

          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