Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8422727
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T03:32:12+00:00 2026-06-10T03:32:12+00:00

In my C# code I read in all id’s of a table into a

  • 0

In my C# code I read in all id’s of a table into a string array ids[i], then update a different column in the table WHERE user_id = id[i].

The problem occurs when the id being read(also passed back into the UPDATE) contains an apostrophe – ‘

       while (rdr.Read()
       {
          ids[i] = rdr.GetValue(0).ToString().Trim();
          ids[i].Replace("'", "''");
          ....

I have also tried ids[i].Replace("'", "\'");
and ids[i].Replace("'", "-"); but I’m sure this will throw off my WHERE as it will look for user_id “O-Test” as opposed to “O’Test”.

My UPDATE SQL is along the lines of:

 UPDATE [User]
 SET first_name = '{1}'
 WHERE [user_id] = '{2}'

Any ideas?

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T03:32:13+00:00Added an answer on June 10, 2026 at 3:32 am

    you need to assign it back to ids[i]

    ids[i] = ids[i].Replace("'", "''");
    

    ids[i].Replace("'", "''"); this will only create a string in memory and discard it, you need to assign it back to ids[i] in your while loop.

    So your code should be:

    while (rdr.Read()
           {
              ids[i] = rdr.GetValue(0).ToString().Trim();
              ids[i] = ids[i].Replace("'", "''");
              ....
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I can read all column Data from code like this ... FMResultSet *rs =
i want to read all records of my table . this is my code
Code is read more often then updated. Writing more readable code is better than
I have this code to load a config file and read all the values
Almost all of the Delphi code I have read has all the class type
I have looked into google and stack over flow and read all the posts
Background All day long I've been trying to solve a problem, I read all
I want to read all XML contents from a file. The code below only
How can I structure the following code so that I can read all of
I use the next code to read all of the elemnts from a file

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.