红袍老师, 录入结果应被Cancel,但还是录入进去了,这是为什么呢?下图 01 已经被使用,不希望在增加出下级

此主题相关图片如下:qq图片20160127143108.png

代码如下
Dim e As object=args(0)
Dim bm As String= e.DataTable.name
Dim dt1,dt2,dt3 As DataTable
dt1=Functions.Execute("loading","Z006配置列",0,"表名='"& bm &"'and 使用表 Is Not null")'已使用的判断
If dt1.DataRows.count>0 Then' 判断是否被使用开始
For Each dr4 As DataRow In dt1.DataRows
If e.DataTable.DataCols.Contains(dr4("列名")) Then
Dim nms() As String=dr4("使用表").Split(",")
Dim lm() As String =dr4("使用表对应列名").Split(",")
For i1 As Integer=0 To nms.Length-1
cmd99.CommandText ="Select Count(*) F rom {"& nms(i1) &"} Where "& lm(i1) &"='"& e.DataRow(dr4("列名")) &"'"
If cmd99.ExecuteScalar > 0 Then
PopMessage("上级编码已在""【" & nms(i1).SubString(5,nms(i1).Length-5) & "】""表中使用,不能增加!","错误", PopIconEnum.Error, 5)
MessageBox.Show(e.NewValue)
MessageBox.Show(e.oldValue)
e.Cancel=True
Return Nothing
Exit For
Else
Continue For
End If
Next
End If
Next
End If