title: How to Catch Duplicate Entry in Primary Key with custom message in VB.NET instead of default exception msg
body: <p>I know that I will need to search for primary key value first in SQL server DB then if value is already there show a msg that record already exists else insert record in DB 
  It would be something like this:</p>
  
  <pre><code>Dim matchISBN As string = txtISBN.Text
  
          da = New SqlDataAdapter("SELECT isbn WHERE isbn =" &amp; matchISBN, cn)
          dt = New DataTable
          da.Fill(dt)
          If isbn = matchISBN Then messagebox.show("record already exist")
          else ....
  </code></pre>
  
  <p>Insert record</p>
  
  <p>I can handle it using try &amp; catch but try &amp; catch will show default message I want my own custom message only for duplicate primary key value! 
  I don't know how to code this any help would be appreciated!</p>