Dim nma() As String = { "1","2","3" } 'A表数据来源列
Dim nmb() As String = { "1","2","3" } 'B表数据接收列
Dim Result As DialogResult
Dim dr As DataRow
Dim dc As String = e.DataCol.Name
Select Case dc
Case "01" ‘01为表A的逻辑列
If e.DataCol.Name = "01" AndAlso e.DataRow("01")=True Then 如果01为true
dr = DataTables("表B").AddNew 表B增加行
For i As Integer = 0 To nma.Length - 1
dr(nmb(i)) = e.DataRow(nma(i)) 将nma的值复制到nmb
dr("4")=e.DataCol.Name 将逻辑列01的列名作为表B4列的值
Next
Else 如果01为false进行条件判断删除表B符合条件的行
If e.DataTables("表B").DataRow.IsNull("5") = False Then '如果表B5列不为空
Result = MessageBox.Show("只有部门主管才能删除行,是否删除行?","提示",MessageBoxButtons.OKCancel,MessageBoxIcon.Question) 提示
If Result = DialogResult.OK Then 选ok表B删除相应行
Tables("表B").Current.Locked = False
DataTables("表B").DeleteFor("[1]= '"& e.DataRow("1") & "'and [5]='" & e.DataCol.Name & "'")
Else
e.Cancel = True '取消删除操作
End If
End If
End If
If e.DataTables("表B").DataRow.IsNull("5") = False Then 老是报错,说无法索引。
请老师看一下涂黄部分该怎么写才对。
主要实现以下功能:
A表是当前表。通过A表中逻辑列的状态实现B表的编辑。
当逻辑列为真时,复制A表内容到B表。
当逻辑列为假时,将B表对应行删除。但删除的前提是B表中的特定列(X)的值为空。不为空值是提示是否删除。
[此贴子已经被作者于2015/6/13 16:13:45编辑过]