title: Find duplicates in a Datagridview
body: <p>I want to search a dgv for duplicates and collect the row numbers of the duplicates in a list (to show it to the user if necessary). this is my code:</p>
  
  <pre><code>Function Check(ByVal dgv As DataGridView)
          Dim Duplicates As New List(Of Tuple(Of Integer, Integer))
          For i As Integer = 1 To dgv.RowCount
              For k As Integer = 1 To dgv.RowCount
                  For j As Integer = 1 To dgv.ColumnCount
  
                      Dim l As Integer
                      If dgv.Rows(i).Cells(j).Value = dgv.Rows(k + 1).Cells(j).Value Then
                          l += l + 1
  
                          If l = dgv.ColumnCount Then
                              Duplicates.Add(Tuple.Create(i, k))
                          End If
                      End If
                  Next
              Next
          Next
  
          Return Duplicates
      End Function
  </code></pre>
  
  <p>Now I have actually two questions:</p>
  
  <ol>
  <li><p>Since I am a beginner I would like to know if this is the best way to search for duplicats</p></li>
  <li><p>I always get the error that <code>Operator '=' is not defined for type 'DBNull'</code>. I know the error but dont know how to handle it. I tried:</p>
  
  <pre><code>        Dim l As Integer
          'DbNull - Check
          Dim first As String
          If IsDBNull(dgv.Rows(i).Cells(j).Value) Then
              first = 0
          Else
              first = dgv.Rows(i).Cells(j).Value
          End If
  </code></pre></li>
  </ol>
  
  <p>Now I checked if <code>first = second</code> instead of <code>dgv.Rows(i).Cells(j).Value = dgv.Rows(k + 1).Cells(j).Value</code> But now I have a type problem, since the db-types are Date, varchar, integer and so on and this gives me conflicts with <code>dim first as string</code>. Anyone knows a way to get rid of the error?</p>
  
  <p>Additional information:
  My dgv 
   - is bound to a datatable which is connected to a sql server
   - has 6 visible and 4 invisible columns</p>