以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  关联表禁止输入不存在父值的数据问题  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=77762)

--  作者:foxstudent
--  发布时间:2015/11/24 22:08:00
--  关联表禁止输入不存在父值的数据问题
 我有AB两个表,关联列是“车号”,A是父表,我在B表的DataColChanging事件设置如下代码,想实现如果B表中输入了A表中不存在的车号会提示:

If e.DataCol.Name = "车号" AndAlso e.NewValue <> Nothing Then
    If e.DataRow.GetParentRow("A") Is Nothing Then
        msgbox("没有这个车")
        e.Cancel = True
    End If
End If

但发现A表里有这个车号,并且已保存,但B表中输入这个车号就提示没有这个车,请问代码错在哪?

--  作者:大红袍
--  发布时间:2015/11/24 22:11:00
--  
If e.DataCol.Name = "车号" AndAlso e.NewValue <> Nothing Then
    Dim fdr As DataRow = DataTables("A").Find("车号 = \'" & e.newValue & "\'")
    If fdr Is Nothing Then
        msgbox("没有这个车")
        e.Cancel = True
    End If
End If

--  作者:foxstudent
--  发布时间:2015/11/24 22:14:00
--  
 可以了,谢谢