title: How to Update SQL Server Table With Data From Other Source (DataTable)
body: <p>I have a <code>DataTable</code> which is generated from .xls table.</p>
  
  <p>I would like to store this <code>DataTable</code> into an existing table in SQL Server database.</p>
  
  <p>I use <code>SqlBulkCopy</code> to store rows which have <strong>unique PK</strong>.</p>
  
  <p>Problem is, I also have other rows which have <strong>same PK</strong> as SQL Server table but contain <strong>cells with different value</strong> compared to SQL Server table.</p>
  
  <p>In short:</p>
  
  <p>Let's say in my <code>DataTable</code> I have a row like this:</p>
  
  <p>id(PK) | name | number</p>
  
  <p>005    | abc  | 123</p>
  
  <p>006    | lge  | 122</p>
  
  <p>For my SQL server I have sth like this;</p>
  
  <p>id(PK) | name | number</p>
  
  <p>004    | cbs  | 345</p>
  
  <p>005    | lks  | 122</p>
  
  <p>Now you see the row <strong>006</strong> can be uploaded straight away into SQL Server using <code>SqlBulkCopy</code>. On the other hand the row <strong>005</strong> can't be inserted using it since SQL server table contains row with identical PK.</p>
  
  <p>Now I tried to manually extract the row. Extract each single cell into an ArrayList then generate an UPDATE Table statement afterwards. However this method seems to be unfeasible as I have so many rows to process.</p>
  
  <p>I am looking for a better method to achieve this goal.</p>
  
  <p>Any help is appreciated.</p>
  
  <p>Thank's</p>