标记删除,而不真正删除,是惯用并且保险的做法,有反悔的机会呀。
如果确实需要物理地删除,又想记录删除数据,以下供参考:
DataRowDeleting
Dim nma() As String = {"A1","A2","A3"} '源表数据来源列
Dim nmb() As String = {"原值A1","原值A2","原值A3"} '记录表数据接收列
Dim nmc() As String = {"新值A1","新值A2","新值A3"} '记录表数据接收列
Dim dr As DataRow = DataTables("数据变动记录").AddNew
For i1 As Integer = 0 To nma.Length - 1
dr(nmb(i1)) = e.DataRow.OriginalValue(nma(i1))
dr("修改方式") = e.DataRow.RowState
dr("行号") = e.DataRow("_Identify")
dr("被修改表") = e.DataTable.Name
dr("修改者") = User.Name
dr("修改日期") = Date.Now()
Next
Select Case dr("修改方式")
Case "Unchanged"
dr("修改方式") = "删除行"
Case Else
Return
End Select