Dim cmd As New SQLCommand Dim dt As DataTable cmd.CommandText = "Select b.姓名, a.客户, a.工具 , Sum(a.数量) as 数量 From {发货} a,{客户} b,{人员} c Where a.客户 = b.客户 And b.姓名 = c.姓名 Group By b.姓名, a.客户, a.工具" dt = cmd.ExecuteReader() For Each r As Row In Tables("人员").Rows For Each dr As DataRow In dt.DataRows If r("姓名") = dr("姓名") AndAlso dr("工具") = "扳手" Then r("扳手") = dr("数量") ElseIf r("姓名") = dr("姓名") AndAlso dr("工具") = "改锥" Then r("改锥") = dr("数量") End If Next Next