title: SqlCommand return value parameter
body: <p>Maybe someone else looking at this code will be able to tell me why the returnID is always 0. I am attempting to retrieve the new ID from the inserted record.</p>
  
  <pre><code>public int AddToInventory(int PartID, int QtyOnHand, int SpokenFor, int LowOrderQty, int HighOrderQty, decimal LastBuyPrice, 
                                      decimal AvgBuyPrice)
  
          {
          ConfigDAL config = new ConfigDAL();
          string connstr = config.GetConnString();
          SqlConnection conn = new SqlConnection(connstr);
  
          string query;
          query = "INSERT INTO Inventory (PartID, QtyOnHand, SpokenFor, LowOrderQty, HighOrderQty, LastBuyPrice, "
                      + "AvgBuyPrice, CreatedOn, CreatedBy, ModifiedOn, ModifiedBy) "
                      + "Values (@PartID, @QtyOnHand, @SpokenFor, @LowOrderQty, @HighOrderQty, @LastBuyPrice, @AvgBuyPrice, "
                      + "@CreatedOn, @CreatedBy, @ModifiedOn, @ModifiedBy)";
  
          SqlCommand cmd = new SqlCommand(query, conn);
          cmd.CommandType = System.Data.CommandType.Text;
          cmd.Parameters.AddWithValue("@PartID", PartID);
          cmd.Parameters.AddWithValue("@QtyOnHand", QtyOnHand);
          cmd.Parameters.AddWithValue("@SpokenFor", SpokenFor);
          cmd.Parameters.AddWithValue("@LowOrderQty", LowOrderQty);
          cmd.Parameters.AddWithValue("@HighOrderQty", HighOrderQty);
          cmd.Parameters.AddWithValue("@LastBuyPrice", LastBuyPrice);
          cmd.Parameters.AddWithValue("@AvgBuyPrice", AvgBuyPrice);
          cmd.Parameters.AddWithValue("@CreatedOn", DateTime.Now);
          cmd.Parameters.AddWithValue("@CreatedBy", GlobalProp.UserName);
          cmd.Parameters.AddWithValue("@ModifiedOn", DateTime.Now);
          cmd.Parameters.AddWithValue("@ModifiedBy", GlobalProp.UserName);
          cmd.Parameters.Add("@ID", SqlDbType.Int).Direction = ParameterDirection.ReturnValue;
          conn.Open();
          cmd.ExecuteNonQuery();
          conn.Close();
          int returnID = (int)cmd.Parameters["@ID"].Value;
  
          return returnID;
          }
  </code></pre>
  
  <p>The record gets inserted to the table fine, but the return value is not right. Am I doing this correctly?</p>
  
  <p>Thanks</p>