当表中的流程编号由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
感觉 上面的方法很繁琐,还有没有简单的办法?
谢谢!