title: DataRow column and string value comparison
body: <p>I have the following problem. I pass values as XML like string and I'm not passing defaults such as false or 0 for numerical columns. So, I create a Dictionary where key is the column name and value is the passed value.</p>
  
  <p>This is my current code</p>
  
  <pre><code>foreach (KeyValuePair&lt;String, String&gt; kvp in rowValues)
       {
          String passedValue = kvp.Value.Trim();
          String rowValue = bookingRow[kvp.Key].ToString().Trim();
          if (passedValue != rowValue)
          {
             // code here
          }
       }
  </code></pre>
  
  <p>The problem is with default values. I can see by debugging my test case that the passedValue is empty and the rowValue is 0 (the column is integer type). So, my question is - how should I re-write the code above to properly convert my passed value into the type of the column. In other words, instead of converting them both to string I need to convert passed value into correct type of DataRow column.</p>
  
  <p>Sample of the passedValue - "".</p>
  
  <p>Sample of the rowValue = "         " (empty string with the length of the column)</p>
  
  <p>Or another example:</p>
  
  <p>Sample of the passedValue = ""</p>
  
  <p>Corresponding rowValue = 0 (the value is Integer in the table)</p>
  
  <p>Both cases should be treated as the same value - no need to write into history.</p>
  
  <p>Thanks to the answers, I am now testing this code:</p>
  
  <pre><code>String passedValue = kvp.Value.Trim();
          var rowValue = bookingRow[kvp.Key];
          if (Convert.ChangeType(passedValue, rowValue.GetType()) != rowValue)
          {
             String rowValueString = rowValue.ToString().Trim();
             if (rowValueString!=passedValue) // Double check to prevent cases of "" vs. "          "
                this.SaveToBookingHistory(booking_id, "M", kvp.Key, rowValueString, passedValue, ref messageText, ref statusCode);
          }
  </code></pre>