OK so I have a datagridview
I get information from a stored proceudre
this will have duplicates

How can I tidy up the code below which deletes duplciates?

'Ensure there are no duplicate SchoolChilds
        icountcount = dgvRegionalGrid.Rows.Count - 1
        iWaitTime = 10
        For icount = 1 To icountcount

            'Check SchoolChild ID delete Duplicates and then wait for  100th of a second

            If dgvRegionalGrid.Item("SchoolChild", icount).Value = dgvRegionalGrid.Item("SchoolChild", icount - 1).Value Then
                dgvRegionalGrid.Rows.RemoveAt(icount)
                
                
            End If

        Next

        For icount = 1 To icountcount

            'Check SchoolChild ID delete Duplicates and then wait for  100th of a second

            If dgvRegionalGrid.Item("SchoolChild", icount).Value = dgvRegionalGrid.Item("SchoolChild", icount - 1).Value Then
                dgvRegionalGrid.Rows.RemoveAt(icount)
                
                
            End If

        Next

        For icount = 1 To icountcount

            'Check SchoolChild ID delete Duplicates and then wait for  100th of a second

            If dgvRegionalGrid.Item("SchoolChild", icount).Value = dgvRegionalGrid.Item("SchoolChild", icount - 1).Value Then
                dgvRegionalGrid.Rows.RemoveAt(icount)
                
                
            End If

        Next

        For icount = 1 To icountcount

            'Check SchoolChild ID delete Duplicates and then wait for  100th of a second

            If dgvRegionalGrid.Item("SchoolChild", icount).Value = dgvRegionalGrid.Item("SchoolChild", icount - 1).Value Then
                dgvRegionalGrid.Rows.RemoveAt(icount)
                
                
            End If

        Next

        For icount = 1 To icountcount

            'Check SchoolChild ID delete Duplicates and then wait for  100th of a second

            If dgvRegionalGrid.Item("SchoolChild", icount).Value = dgvRegionalGrid.Item("SchoolChild", icount - 1).Value Then
                dgvRegionalGrid.Rows.RemoveAt(icount)
                
                
            End If

        Next

        For icount = 1 To icountcount

            'Check SchoolChild ID delete Duplicates and then wait for  100th of a second

            If dgvRegionalGrid.Item("SchoolChild", icount).Value = dgvRegionalGrid.Item("SchoolChild", icount - 1).Value Then
                dgvRegionalGrid.Rows.RemoveAt(icount)
                
                
            End If

        Next

        For icount = 1 To icountcount

            'Check SchoolChild ID delete Duplicates and then wait for  100th of a second

            If dgvRegionalGrid.Item("SchoolChild", icount).Value = dgvRegionalGrid.Item("SchoolChild", icount - 1).Value Then
                dgvRegionalGrid.Rows.RemoveAt(icount)
                
                
            End If

        Next

OMG. Can't you fix the sp? Like "SELECT DISTINCT(SchoolChildID)..." or "SELECT DISTINCT(SchoolChild)..."

This article has been dead for over six months. Start a new discussion instead.