我想只显示重复的行,并删除GridView中的所有单行(非公开的)
我的代码是:
Private Sub load_table()
MysqlConn = New MySqlConnection
MysqlConn.ConnectionString = "server=localhost;userid=root;password=nassa640088;database=testing"
Dim SDA As New MySqlDataAdapter
Dim dbDataSet As New DataTable
Dim bSource As New BindingSource
Try
MysqlConn.Open()
Dim Query As String
Query = "select * from testing.login"
COMMAND = New MySqlCommand(Query, MysqlConn)
SDA.SelectCommand = COMMAND
SDA.Fill(dbDataSet)
bSource.DataSource = dbDataSet
DataGridView1.DataSource = bSource
SDA.Update(dbDataSet)
MysqlConn.Close()
Catch ex As MySqlException
MessageBox.Show(ex.Message)
Finally
MysqlConn.Dispose()
End Try
End Sub
答案 0 :(得分:1)
在这种情况下,使用group by
更改您的查询(假设有一个id
列)
select * from testing.login where id in (
select id
from testing.login
group by id
having count(id) > 1 );