title: How to check for duplicate value in database when importing vb.net
body: <pre><code>            For i As Integer = 0 To dgclassinfo.Rows.Count - 1
  
                  LRN = dgclassinfo.Rows(i).Cells(2).Value.ToString
                  Lname = dgclassinfo.Rows(i).Cells(3).Value.ToString
                  Fname = dgclassinfo.Rows(i).Cells(4).Value.ToString
                  Mname = dgclassinfo.Rows(i).Cells(5).Value.ToString
  
  
                  comm.CommandText = "insert into g7(LRN,Lname,Fname,Mname ) values('" &amp; LRN &amp; "','" &amp; Lname &amp; "','" &amp; Fname &amp; "','" &amp; Mname &amp; "')"
                  comm.ExecuteNonQuery()
  
  
  
              Next
  </code></pre>
  
  <p>I used to code above to import my data. Using dgv. My data is databound. for additional info. When I import the file it reads the value of the excel and displays in the dgv in which i insert the data using the for loop above. I think I need to use mydr.hasrows but I have no idea on how to do this using for loop. How can I check for duplicate records every row? LRN is my pk.</p>
  
  <p>Any help will be appreciated.</p>