Problem inserting ' and ; in DB

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • asivakrupa
    New Member
    • Apr 2009
    • 14

    Problem inserting ' and ; in DB

    Hi,

    I am inserting a comments value i.e a field which contains comments into a DB which is provided by the user as input.

    If the value for the field contains quotes (both " and ') as well as semi colon (;), the results in an error.

    Please help me include these special characters into the DB.

    Thanks in advance.
  • kunalsmehta
    New Member
    • Apr 2009
    • 6

    #2
    insert into @table1 values('03-11-2004',102252271 ,100061, ';Eli NewName''"')

    Comment

    • asivakrupa
      New Member
      • Apr 2009
      • 14

      #3
      I don understand what you have given. Please explain me more on this issue.

      Comment

      • kunalsmehta
        New Member
        • Apr 2009
        • 6

        #4
        this is the way u can enter special characters in db.
        for inserting ' you need to insert ''
        thats it

        Comment

        • asivakrupa
          New Member
          • Apr 2009
          • 14

          #5
          Yeah i found out this jus nw. I am able to insert the value but while retrieving the same from the DB i get lot of errors. Do u have any idea abt ths?

          Comment

          • kunalsmehta
            New Member
            • Apr 2009
            • 6

            #6
            What errs r u getting. post the errs with test data

            Kunal

            Comment

            • asivakrupa
              New Member
              • Apr 2009
              • 14

              #7
              Hi,

              The value I am trying to retrieve is a'b'c. I used the replace() fn by replacing ( ' ) with ( '' ) at the time of insertion into the DB.

              This is the error that i get when i try to retrieve the value from the DB. The query is as follows:
              select name from Table1; (the value of name here is a'b'c)
              Incorrect syntax near '='. (severity 15)

              Please help me out.
              Thanks in advance.

              Comment

              • kunalsmehta
                New Member
                • Apr 2009
                • 6

                #8
                declare @table1 table (date datetime,Agrid int,chkId int,name varchar(18) )



                insert into @table1 values('03-11-2004',102252271 ,100061, 'a''b''c')
                insert into @table1 values('03-11-2004',102252271 ,100842, 'Eli OldName')
                insert into @table1 values('11-11-2004',102252271 ,100843, 'Eli OldName') ;
                select * from @table1 where name ='a''b''c'


                This will help u. worked for me
                Kunal

                Comment

                Working...