title: How to detect it was duplicate entry on VB.NET?
body: <p>I have a problem on making avoid or detect duplicate data entry in VB.NET using SQL Server, and also pop up message when there is duplicate entry.</p>
  
  <p>This is my add button code:</p>
  
  <pre class="lang-vb prettyprint-override"><code>Dim sql = "INSERT INTO studentAttendence(studentID, date, time, subject, attendence) " &amp;
      "VALUES(@studentID, @date, @time, @subject, @attendence)" &amp;
      "WHERE NOT EXISTS(SELECT * FROM studentAttendence WHERE studentID = @studentID)"
  
  Using cn As New SqlConnection("My sql Connection string")
      Dim commands As SqlCommand = New SqlCommand(sql, cn)
  
      commands.Parameters.Add("@studentID", SqlDbType.NVarChar).Value = TextBox1.Text
      commands.Parameters.Add("@date", SqlDbType.NVarChar).Value = DateTimePicker1.Text
      commands.Parameters.Add("@time", SqlDbType.NVarChar).Value = DateTimePicker2.Text
      commands.Parameters.Add("@subject", SqlDbType.NVarChar).Value = ComboBox1.Text
      commands.Parameters.Add("@attendence", SqlDbType.NVarChar).Value = ComboBox2.Text
  
      commands.ExecuteNonQuery()
  End Using
  </code></pre>
  
  <p>Or is there any other methods for making avoid duplicate entries. I just want to avoid same date and subject of a student to add. So I can only add subject on the next date if I already add subject on today's date of studentID.</p>