title: Escape single apostrophe when using SELECT from SQL, into an array in C# then UPDATE
body: <p>In my C# code I read in all id's of a table into a string array <code>ids[i]</code>, then update a different column in the table WHERE user_id = id[i].</p>
  
  <p>The problem occurs when the id being read(also passed back into the <code>UPDATE</code>) contains an apostrophe - '</p>
  
  <pre><code>       while (rdr.Read()
         {
            ids[i] = rdr.GetValue(0).ToString().Trim();
            ids[i].Replace("'", "''");
            ....
  </code></pre>
  
  <p>I have also tried <code>ids[i].Replace("'", "\'");</code><br>
  and <code>ids[i].Replace("'", "-");</code> but I'm sure this will throw off my WHERE as it will look for user_id "O-Test" as opposed to "O'Test".</p>
  
  <p>My UPDATE SQL is along the lines of:  </p>
  
  <pre><code> UPDATE [User]
   SET first_name = '{1}'
   WHERE [user_id] = '{2}'
  </code></pre>
  
  <p>Any ideas?</p>
  
  <p>Thanks.</p>