title: Violation of UNIQUE KEY constraint Cannot insert duplicate key in object
body: <p>------------------------here is my sql procedue to update table------------------------</p>
  
  <pre><code>create procedure sp_stepUpdate
  @ID int,
  @StepOrder int
  
  AS
  BEGIN  
  
  
  IF OBJECT_ID('tempdb.dbo.#UpdateBatch','u') IS NOT NULL
  begin
  DROP TABLE #UpdateBatch
  end
  
  IF OBJECT_ID('tempdb.dbo.#UpdateBatch2','u') IS NOT NULL
  begin
  DROP TABLE #UpdateBatch2
  end
  
  create table #UpdateBatch2
  (
  ID int,
  StepOrder int
  )
  
  insert into #UpdateBatch2 values (@ID,@StepOrder)
  
  Select *,ROW_NUMBER() OVER(ORDER BY ID) as newIID into #UpdateBatch
  from #UpdateBatch2
  
  set identity_insert [ODM_BatchSteps] ON
  
  Update [ODM_BatchSteps]
  set [StepOrder] = newIID
  From #UpdateBatch 
  where [ODM_BatchSteps].ID = #UpdateBatch.ID
  
  set identity_insert [ODM_BatchSteps] off
  END
  go
  </code></pre>
  
  <p>---------------and here is my code in the program to get the new order from the list------</p>
  
  <pre><code>    connection.Open()
  
  
      For Each item As ListViewItem In ListView1.Items
  
          Dim command As SqlCommand = New SqlCommand("sp_stepUpdate", connection)
          command.CommandType = CommandType.StoredProcedure
          command.Parameters.AddWithValue("@ID", item.SubItems(0).Text)
          command.Parameters.AddWithValue("@StepOrder", item.SubItems(1).Text)
          command.ExecuteNonQuery()
      Next
  </code></pre>
  
  <p>i get Violation of UNIQUE KEY constraint when tryin to update the table with the new order from my listview</p>
  
  <p>-----------here is the the table the order iam trying to update-----</p>
  
  <pre><code>    create table [dbo].[ODM_BatchSteps]
  (
  [ID] uniqueidentifier primary key not null default newid(),
  [StepOrder]int ,
  [StepType]int,
  [StepGrid]nvarchar(max),
  [BatchGrid]int,
  foreign key (BatchGrid) REFERENCES ODM_Batches(ID)
  )
  </code></pre>