以文本方式查看主题 - Foxtable(狐表) (http://foxtable.com/bbs/index.asp) -- 专家坐堂 (http://foxtable.com/bbs/list.asp?boardid=2) ---- [求助] 条件复制其他表数据到指定表中命令 (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=57981) |
-- 作者:wumingrong1 -- 发布时间:2014/10/9 15:02:00 -- [求助] 条件复制其他表数据到指定表中命令 我希望实现:如果“机房板件端口表”中新增加未保存的行与“板件端口列表”中存在‘设备名称’ ‘设备型号’ ‘板件型号’相同的行;就将”板件端口列表“中符号条件的行复制到”机房板件端口表“中去;但是下面的命令却是把所有的数据都复制了一遍;把原来”机房板件端口表“中存在的数据全部覆盖掉了;我这个命令该怎么修改? DataTables("机房板件端口表").DataRows.Clear For Each dr As DataRow In DataTables("机房设备板件表").Select("机房名称 is not null") Dim drs As List(Of DataRow) = DataTables("板件端口列表").Select("设备名称 = \'" & dr("设备名称") & "\' and 设备型号 = \'" & dr("设备型号") & "\' and 板件型号 = \'" & dr("板件型号") & "\'") For Each r As DataRow In drs Dim ndr As DataRow = DataTables("机房板件端口表").AddNew ndr("机房名称") = dr("机房名称") ndr("设备名称") = r("设备名称") ndr("设备型号") = r("设备型号") ndr("设备编号") = dr("设备编号") ndr("端口类型") = r("端口类型") ndr("端口编号") = r("端口编号") ndr("板件名称") = r("板件名称") ndr("板件型号") = r("板件型号") ndr("板件槽位") = dr("板件槽位") ndr("板件型号") = r("板件型号") Next Next |
-- 作者:有点甜 -- 发布时间:2014/10/9 15:05:00 -- 判断行状态,参考
http://www.foxtable.com/help/topics/0428.htm
|
-- 作者:有点甜 -- 发布时间:2014/10/9 15:07:00 -- For Each dr As DataRow In DataTables("机房设备板件表").Select("机房名称 is not null") Dim drs As List(Of DataRow) = DataTables("板件端口列表").Select("设备名称 = \'" & dr("设备名称") & "\' and 设备型号 = \'" & dr("设备型号") & "\' and 板件型号 = \'" & dr("板件型号") & "\'") For Each r As DataRow In drs If r.RowState = DataRowState.Added OrElse r.RowState = DataRowState.Modified Then Dim ndr As DataRow = DataTables("机房板件端口表").AddNew ndr("机房名称") = dr("机房名称") ndr("设备名称") = r("设备名称") ndr("设备型号") = r("设备型号") ndr("设备编号") = dr("设备编号") ndr("端口类型") = r("端口类型") ndr("端口编号") = r("端口编号") ndr("板件名称") = r("板件名称") ndr("板件型号") = r("板件型号") ndr("板件槽位") = dr("板件槽位") ndr("板件型号") = r("板件型号") End If Next Next |