title: Update DATETIME column where said DATETIME < current DATETIME
body: <p>I've got an ASP.NET 4.0 C# web application that allows multiple users to update rows in the SQL Server DB at the same time. I'm trying to come up with a quick system that will stop USER1 from updating a row that USER2 updated since USER1's last page refresh.</p>
  
  <p>The problem I'm having is that my web application always updates the row, even when I think it shouldn't. But when I manually run the query it only updates when I think it should.</p>
  
  <p>This is my SQL query in C#:</p>
  
  <pre><code>SQLString = "update statuses set stat = '" + UpdaterDD.SelectedValue +
              "', tester = '" + Session["Username"].ToString() +
              "', timestamp_m = '" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") +
              "' where id IN (" + IDs + ") and timestamp_m &lt; '" + PageLoadTime + "';";
  </code></pre>
  
  <p>And here's a 'real world' example:</p>
  
  <pre><code>SQLString = "update statuses set stat = 'PASS', tester = 'tester007',
               timestamp_m = '2013-01-23 14:20:07.221' where id IN (122645) and
               timestamp_m &lt; '2013-01-23 14:20:06.164';"
  </code></pre>
  
  <p>My idea was that this will only update if no other user has changed this row since the user last loaded the page. I have formatted <code>PageLoadTime</code> to the same formatting as my SQL Server DB, as you can see with <code>DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")</code>, but something still isn't right.</p>
  
  <p>Does anyone know why I get two different results? Is what I want to do even possible?</p>