Programming for Everybody: Visual Basic.net: get duplicate records in SQL Server[ with source code ]

Visual Basic.net: get duplicate records in SQL Server[ with source code ]

 


Imports System.Data.SqlClient
Public Class Form1
    Dim conn As New SqlConnection("Data Source=.;Initial Catalog=Names;Integrated Security=True")
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        If conn.State = ConnectionState.Closed Then
            conn.Open()

        End If

        Dim cmd1 As New SqlCommand("select * from table1 where name In (Select name from table1 Group by name having (Count(*)>1)) order by name", conn)

        Dim da As New SqlDataAdapter
        Dim dt As New DataTable
        da.SelectCommand = cmd1
        dt.Clear()
        da.Fill(dt)
        DataGridView1.DataSource = dt

        conn.Close()






    End Sub
End Class

No comments:

Post a Comment