title: c# update statement with where clause
body: <p>I have a database with ordernumber &amp; trackingnumber. The ordernumber is already completed.</p>
  
  <p>I have the following code to update a trackingnumber column in my database, but it must only update where the ordernumber matches what the user types in. (The user enters an order number and a tracking number in default.aspx)</p>
  
  <p>At the moment the code seems to work ok. but i have noticed a problem im not sure how to fix:
  the ordernumber column only goes up to number 3578, so i would expect that if the user typed in 3579 or higher, or indeed anything that doesn't match an ordernumber, then an exception will be thrown, but instead it says "updated". However there is no ordernumber of 3579, it just doesn't exist. so is it my SQL query that is not working properly? as i have the "Where" clause in. or is there something else i have missed?</p>
  
  <p>Code:</p>
  
  <pre><code>    using System;
      using System.Collections.Generic;
      using System.Linq;
      using System.Data;
      using System.Data.SqlClient;
      using System.Configuration;
      using System.Web;
      using System.Web.UI;
      using System.Web.UI.WebControls;
  
      namespace tracking
      {
          public partial class _Default : Page
          {
      protected void Page_Load(object sender, EventArgs e)
      {
          errorLabel.Visible = false;
          SuccessLabel.Visible = false;
      }
  
      protected void submitBtn_Click(object sender, EventArgs e)
      {
          int _orderID = Convert.ToInt32(orderID.Text);
          string _trackingID = trackingNumber.Text;
  
          SqlConnection myConnection = new SqlConnection("Data Source=MYDATABASESERVER;Initial Catalog=DATABASENAME;User ID=USERNAME;Password=PASSWORD");
          SqlCommand myCommand = new SqlCommand("UPDATE Shipment SET TrackingNumber = @tracking WHERE OrderId = @order", myConnection);
  
          try
          {
              myConnection.Open();
              myCommand.Parameters.AddWithValue("@order", _orderID);
              myCommand.Parameters.AddWithValue("@tracking", _trackingID);
              myCommand.ExecuteNonQuery();
              myConnection.Close();
              SuccessLabel.Text = "Thank you, tracking details have been updated";
              SuccessLabel.Visible = true;
              orderID.Text = "";
              trackingNumber.Text = "";
          }
          catch (Exception f)
          {
              errorLabel.Text =  f.Message.ToString();
              errorLabel.Visible = true;
              return;
  
          }
  
  
  
  
  
  
      }
  }
  </code></pre>
  
  <p>}</p>