试试,测试前备份一下数据
Dim cmd As new SQLCommand
cmd.CommandText = "select 部品ID from {表A} group by 部品ID having count(使用机器1) > 1"
Dim dt As DataTable = cmd.ExecuteReader()
If dt.DataRows.Count > 0 Then
Dim dr2 As DataRow
For Each dr As DataRow In dt.DataRows
Dim drs As List(Of DataRow) = DataTables("表A").Select("部品ID = '" & dr("部品ID") & "'")
dr2 = drs(0)
Dim idx As Integer = 1
For i As Integer = 0 To drs.Count - 1
If drs(i).Isnull("使用机器1") = False Then
dr2("使用机器" & idx) = drs(i)("使用机器1")
idx += 1
End If
Next
For i As Integer = 1 To drs.Count - 1
drs(i).Delete
Next
Next
End If
[此贴子已经被作者于2016/12/23 14:13:22编辑过]