以文本方式查看主题 - Foxtable(狐表) (http://foxtable.com/bbs/index.asp) -- 专家坐堂 (http://foxtable.com/bbs/list.asp?boardid=2) ---- 交换 (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=108982) |
-- 作者:happyft -- 发布时间:2017/11/1 20:36:00 -- 交换 当表中的流程编号由2变成3时更新后台数据表中的对应的数据,采用的方法是先分别按2和3获取后台数据表的_Identify集合, 然后用这个_Identify集合作为条件分别更新,如下是代码: If e.DataRow.RowState <> DataRowState.Added AndAlso e.DataRow("Fid") <> e.DataRow.OriginalValue("Fid") Then \'如果不是新增行且新旧值不同 Dim flt,flt2,ids,ids2 As String Dim dt As DataTable Dim cmd As New SQLCommand cmd.ConnectionName = Mydata \'A---更新数据表中的流程编号------------------------------------------------------ flt = "sys_Fbh = " & e.DataRow.OriginalValue("Fid") & " and (sys_Fzt = \'待处理\' or sys_Fzt = \'退回\')" \'旧流程编号的行 flt2 = "sys_Fbh = " & e.DataRow("Fid") & " and (sys_Fzt = \'待处理\' or sys_Fzt = \'退回\')" \'新流程编号的行 cmd.CommandText = "se lect _Identify from " & e.DataRow("tbN") & " Where " & flt dt = cmd.ExecuteReader \'--分别集合新旧编号的行的_identify If dt.DataRows.count > 0 Then For Each dr As DataRow In dt.datarows ids + = dr("_Identify") & "," Next ids = ids.trim(",") End If cmd.CommandText = "se lect _Identify from " & e.DataRow("tbN") & " Where " & flt2 dt = cmd.ExecuteReader If dt.DataRows.count > 0 Then For Each dr As DataRow In dt.datarows ids2 + = dr("_Identify") & "," Next ids2 = ids2.trim(",") End If \'分别更新数据表中的流程编号 cmd.CommandText = "Update {" & e.DataRow("tbN") & "} Se t sys_Fbh = " & e.DataRow("Fid") & " Where _Identify in (" & flt & ")" \'旧编号的行更新为新编号 cmd.ExecuteNonQuery() cmd.CommandText = "Update {" & e.DataRow("tbN") & "} Se t sys_Fbh = " & e.DataRow.OriginalValue("Fid") & " Where _Identify in (" & flt2 & ")" \'新编号的行更新为旧编号 cmd.ExecuteNonQuery() End If 感觉 上面的方法很繁琐,还有没有简单的办法? 谢谢!
|
-- 作者:有点甜 -- 发布时间:2017/11/1 21:22:00 -- 没必要这么麻烦吧?
把2变成-1,把3变成2,-1变成3,即可。三条update语句。 |