title: Violation of PRIMARY KEY constraint. Cannot insert duplicate key in object
body: <p>I inherited a project and I'm running into a SQL error that I'm not sure how to fix.</p>
  <p>On an eCommerce site, the code is inserting order shipping info into another database table.</p>
  <p>Here's the code that is inserting the info into the table:</p>
  <pre class="lang-cs prettyprint-override"><code>string sql = &quot;INSERT INTO AC_Shipping_Addresses   
  (pk_OrderID, FullName, Company, Address1, Address2, City, Province, PostalCode, CountryCode, Phone, Email, ShipMethod, Charge_Freight, Charge_Subtotal)  
  VALUES (&quot; + _Order.OrderNumber;
  sql += &quot;, '&quot; + _Order.Shipments[0].ShipToFullName.Replace(&quot;'&quot;, &quot;''&quot;) + &quot;'&quot;;
  if (_Order.Shipments[0].ShipToCompany == &quot;&quot;)
  {
    sql += &quot;, '&quot; + _Order.Shipments[0].ShipToFullName.Replace(&quot;'&quot;, &quot;''&quot;) + &quot;'&quot;;
  }
  else
  {
    sql += &quot;, '&quot; + _Order.Shipments[0].ShipToCompany.Replace(&quot;'&quot;, &quot;''&quot;) + &quot;'&quot;;
  }
  sql += &quot;, '&quot; + _Order.Shipments[0].Address.Address1.Replace(&quot;'&quot;, &quot;''&quot;) + &quot;'&quot;;
  sql += &quot;, '&quot; + _Order.Shipments[0].Address.Address2.Replace(&quot;'&quot;, &quot;''&quot;) + &quot;'&quot;;
  sql += &quot;, '&quot; + _Order.Shipments[0].Address.City.Replace(&quot;'&quot;, &quot;''&quot;) + &quot;'&quot;;
  sql += &quot;, '&quot; + _Order.Shipments[0].Address.Province.Replace(&quot;'&quot;, &quot;''&quot;) + &quot;'&quot;;
  sql += &quot;, '&quot; + _Order.Shipments[0].Address.PostalCode.Replace(&quot;'&quot;, &quot;''&quot;) + &quot;'&quot;;
  sql += &quot;, '&quot; + _Order.Shipments[0].Address.Country.Name.Replace(&quot;'&quot;, &quot;''&quot;) + &quot;'&quot;;
  sql += &quot;, '&quot; + _Order.Shipments[0].Address.Phone.Replace(&quot;'&quot;, &quot;''&quot;) + &quot;'&quot;;
  if (_Order.Shipments[0].ShipToEmail == &quot;&quot;)
  {
    sql += &quot;,'&quot; + _Order.BillToEmail.Replace(&quot;'&quot;, &quot;''&quot;) + &quot;'&quot;;
  }
  else
  {
    sql += &quot;,'&quot; + _Order.Shipments[0].ShipToEmail.Replace(&quot;'&quot;, &quot;''&quot;) + &quot;'&quot;;
  }
  sql += &quot;, '&quot; + _Order.Shipments[0].ShipMethod.Name.Replace(&quot;'&quot;, &quot;''&quot;) + &quot;'&quot;;
  sql += &quot;, &quot; + shippingAmount;
  sql += &quot;, &quot; + _Order.ProductSubtotal.ToString() + &quot;)&quot;;
  bll.dbUpdate(sql);
  </code></pre>
  <p>It is working correctly, but it is also outputting the following SQL error:</p>
  <blockquote>
  <p>Violation of PRIMARY KEY constraint 'PK_AC_Shipping_Addresses'. Cannot insert
  duplicate key in object 'dbo.AC_Shipping_Addresses'. The duplicate key value
  is (165863).</p>
  </blockquote>
  <p>From reading similar questions, it seems that I should declare the ID in the statement.</p>
  <p>Is that correct? How would I adjust the code to fix this issue?</p>