title: SQL Server : update not updating table c# no error
body: <p>I'm trying to update a table of items:</p>
  
  <pre><code>public void updateDatabase(Item item)
  {
      string sqlString = "UPDATE Items Set Quantity = '" + item.Quantity.ToString().Trim() + "' " + "WHERE ItemID = '" + item.ItemID.Trim() + "'";
      //string sqlStringParam = "UPDATE Items Set Quantity = @quant WHERE ItemID = @id";
  
      //Create &amp; execute the update command
      using (SqlCommand sc = new SqlCommand(sqlString, mainConn))
      {
          //sc.Parameters.AddWithValue("@quant", item.Quantity);
          //sc.Parameters.AddWithValue("@id", item.ItemID);
          Console.WriteLine(sc.CommandText.ToString());
          UpdateDataSource(sc, table);
      }
      Console.WriteLine("done");
  }
  </code></pre>
  
  <p>This sends the command to the database class to execute the query:</p>
  
  <pre><code>protected bool UpdateDataSource(SqlCommand command, string table)
  {
      bool success;
  
          try
          {
              if (mainConn.State != ConnectionState.Open)
              {
                  mainConn.Open();
              }
  
              Console.WriteLine(command.CommandText);
  
              command.CommandType = CommandType.Text;
              Console.WriteLine(command.ExecuteNonQuery());
  
              mainConn.Close();
              success = true;
          }
          catch (Exception e)
          {
              MessageBox.Show(e.Message + " " + e.StackTrace, "Error Updating Database");
              mainConn.Close();
              success = false;
          }
          finally
          {
          mainConn.Close();
          }
      return success;
  }
  </code></pre>
  
  <p>As you can see I've tried both the concat method and the paramaterized method, both won't update the table. Here is the output when trying to update 2 items:</p>
  
  <pre><code>UPDATE Items Set Quantity = '4' WHERE ItemID = '1122'
  UPDATE Items Set Quantity = '4' WHERE ItemID = '1122'
  1
  done
  UPDATE Items Set Quantity = '9' WHERE ItemID = '1155'
  UPDATE Items Set Quantity = '9' WHERE ItemID = '1155'
  1
  done
  </code></pre>
  
  <p>To me, it seems like it should be updating the table. I've even run an exact copied statement from above as a single query and it updates the table.</p>
  
  <p>The <code>ExecuteNonQuery</code> even returns a 1.</p>