Results 1 to 5 of 5
  1. #1
    Join Date
    Feb 2003
    Location
    Calgary, Alberta.
    Posts
    11

    Unanswered: Insert/Update data with "'"

    Hi,

    Let's say.. I have a string defined in C++ such as this:

    TCHAR tszQuery[] = _T("UPDATE EMPLOYEE
    SET EMPNO = '%s'
    WHERE ID = %d");

    now, I mapped this string with sprintf with a string contains such as this:

    "It's great"

    when this becomse %s part of above query.. it has.. EMPNO = 'It's great' ..

    but, as you see, there is a problem with " ' ".

    well, now, I have SQL error with above case. I am using eVC, and DB2e.

    Now, what shoud I do to avoid the error?

    I tried adding escape character like It\'s great.

    but, it did not work.

    Thanks.

  2. #2
    Join Date
    Apr 2003
    Location
    Singapore
    Posts
    59

    Re: Insert/Update data with "'"

    Hi,
    the escape character is ' and not \
    try using "I''ts great"

    hth

    cheers
    brat

    Originally posted by xgamen
    Hi,

    Let's say.. I have a string defined in C++ such as this:

    TCHAR tszQuery[] = _T("UPDATE EMPLOYEE
    SET EMPNO = '%s'
    WHERE ID = %d");

    now, I mapped this string with sprintf with a string contains such as this:

    "It's great"

    when this becomse %s part of above query.. it has.. EMPNO = 'It's great' ..

    but, as you see, there is a problem with " ' ".

    well, now, I have SQL error with above case. I am using eVC, and DB2e.

    Now, what shoud I do to avoid the error?

    I tried adding escape character like It\'s great.

    but, it did not work.

    Thanks.

  3. #3
    Join Date
    Jan 2003
    Posts
    1,605
    Hi,

    I have very similar problem.

    How to insert into table values with ' character and how to insert the values with " character?

    How to write select statemenst go get this two characters from database?

    Thanks,
    Grofaty

  4. #4
    Join Date
    Feb 2003
    Location
    Calgary, Alberta.
    Posts
    11
    Originally posted by grofaty
    Hi,

    I have very similar problem.

    How to insert into table values with ' character and how to insert the values with " character?

    How to write select statemenst go get this two characters from database?

    Thanks,
    Grofaty
    Also, I could use BindParameter() to bind a character column with the variable for update as I did for insert.. it then took care of them.

  5. #5
    Join Date
    Jan 2003
    Posts
    1,605
    Hi,

    Could you be so kind and send some kind of example?

    Thanks,
    Grofaty

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •