title: C# ignores trailing space in value when using DataTable's Select command
body: <p>When I try to access a value with a space at the end from a <code>DataTable</code>, C# fails to recognize it. To clarify, the <code>value</code> variable in: <code>Select(columnName + " = '" + value + "'")[0][newColumnName].ToString();</code> must not have a trailing space, or C# will produce inaccurate results.</p>
  
  <p>Thing is, I have a LINQ equivalent which works okay, but I'm not sure how to create an equivalent 'set' function.</p>
  
  <p>So an answer would either be a way to fix this apparent bug in C#, or help write an equivalent LINQ <code>set()</code> function to my LINQ <code>get()</code> (i.e. without using <code>Select()</code> ). Both solutions would be even better.</p>
  
  <p>Here's the fully working code you can use to show what I have so far, and reproduce the bug. The output I get is: green, red, red, also-red ....when it should be: green, red, also-red, also-red</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Data;
  
  namespace datatable_trailing_space_bug
  {
      class Program
      {
          static void Main(string[] args)
          {
              SuperDataTable table = new SuperDataTable();
  
              /////////////////////////////
              table.Columns.Add("fruitName", typeof(string));
              table.Columns.Add("colour", typeof(string));
  
              //////////////  name, type, colour, length
              table.Rows.Add("apple", "green");
              table.Rows.Add("banana", "yellow");
              table.Rows.Add("strawberry", "red");
              table.Rows.Add("strawberry ", "also-red");
  
              Console.WriteLine(table._get_FAILS_ON_TRAILING_SPACE("fruitName", "apple", "colour"));          // This works - "green"
              Console.WriteLine(table._get_FAILS_ON_TRAILING_SPACE("fruitName", "strawberry", "colour"));     // This works - "red"
              Console.WriteLine(table._get_FAILS_ON_TRAILING_SPACE("fruitName", "strawberry ", "colour"));    // This fails due to trailing space - "red" (should be "also-red")
              Console.WriteLine(table._get_WORKS("fruitName", "strawberry ", "colour"));                      // This works - "also-red"
  
  
              Console.ReadLine();
          }
  
  
      }
  
  
      public class SuperDataTable : DataTable
      {
          public SuperDataTable()
          {
          }
          public string _get_FAILS_ON_TRAILING_SPACE(string columnName, string value, string newColumnName)       {
              value = value.Replace("'", "''");
              return Select(columnName + " = '" + value + "'")[0][newColumnName].ToString();
          }
          public void _set_FAILS_ON_TRAILING_SPACE(string columnName, string value, string newColumnName, string newValue) {
              value = value.Replace("'", "''");
              Select(columnName + "='" + value + "'")[0][newColumnName] = newValue;
          }
  
          public string _get_WORKS(string columnName, string value, string newColumnName) {
              string output = this.AsEnumerable()
                  .Where(s =&gt; s.Field&lt;string&gt;(columnName).Equals(value))
                  .Select(s =&gt; s.Field&lt;string&gt;(newColumnName)).FirstOrDefault();
              return output;
          }
          public void _set_WORKS(string columnName, string value, string newColumnName, string newValue) {
              // Enter working code here please.
          }
  
      }
  }
  </code></pre>