title: Handle Listview insert duplicate sql error ASP.NET
body: <p>This is my first time asking a question and I've been searching for 2 days to find an answer. Hopefully one of you masters can assist. </p>
  
  <p>I have a 4 column listview populated from a sql table. The table doesn't allow duplicates. I simply want to be able to catch that error and give a friendly message to the user that the item is already in the list. I have found multiple solutions that don't work (probably my error). </p>
  
  <p>Below is the one that I had the most hope for... but nothing. </p>
  
  <p>Still getting "Violation of PRIMARY KEY constraint 'PK_tbl.associateNames'. Cannot insert duplicate key in object 'dbo.tbl.associateNames'.
  The statement has been terminated"</p>
  
  <pre><code>   Protected Sub listviewInserting_itemInserted(ByVal sender As Object, ByVal e As ListViewInsertEventArgs)
  
  
      Dim con As New SqlConnection
      Dim cmd As New SqlCommand
      Try
          con.ConnectionString = "Data Source=server\instance; Initial Catalog=sears;User Id=johnnyFive;Password=alive;"
          con.Open()
          cmd.Connection = con
          cmd.CommandText = "INSERT INTO [tbl.associateNames] ([orderIssuer], [associateName], [department]) VALUES (@orderIssuer, @associateName, @department)"
          cmd.ExecuteNonQuery()
      Catch ex As SqlException
          MsgBox("Duplicate Entry found", MsgBoxStyle.Information, "Dups")
          e.Cancel = True
      End Try
  
  End Sub
  </code></pre>
  
  <p>ANY suggestions would be appreciated! Thanks.</p>