以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  一个父表多个子表的删除  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=59434)

--  作者:seal51
--  发布时间:2014/11/4 11:21:00
--  一个父表多个子表的删除

比如有一个主表, 关联了三个明细表(明细表1, 明细表2, 明细表3), 那个主表的删除代码如何写?

我知道一个明细表的写法:

 

If Tables("主表.明细表1").Rows.Count > 0 Then
    MessageBox.Show("该主表有明细项,请先删除明细项再删除主表!")
    Return
Else
    If MessageBox.Show("是否删除?","请确认",MessageBoxButtons.YesNo,MessageBoxIcon.Question) = DialogResult.Yes Then
        Tables("主表").Current.Delete
    End If
End If


--  作者:有点甜
--  发布时间:2014/11/4 11:26:00
--  

 什么意思?

 

 子表行.DataRow.GetParentRow("主表名").Delete

[此贴子已经被作者于2014-11-4 11:26:43编辑过]

--  作者:seal51
--  发布时间:2014/11/4 11:29:00
--  
只有删除明细表的数据后才能删除主表的数据
--  作者:seal51
--  发布时间:2014/11/4 11:30:00
--  
只有删除明细表1,明细表2, 明细表3的关联数据后才能删除主表的数据, 否则不能删除主表的数据, 这个代码如何写
--  作者:seal51
--  发布时间:2014/11/4 11:39:00
--  
甜老师, 给看看吧
--  作者:有点甜
--  发布时间:2014/11/4 11:43:00
--  

 1、分别在明细表1、明细表2、明细表3中,查找是否还有主表的数据;

 

 2、如果全部没有,就把主表数据删除。


--  作者:seal51
--  发布时间:2014/11/4 12:13:00
--  

If Tables("主表.明细表1").Rows.Count > 0  or Tables("主表.明细表2").Rows.Count > 0  or Tables("主表.明细表3").Rows.Count > 0  Then
    MessageBox.Show("该主表有明细项,请先删除明细项再删除主表!")
    Return
Else
    If MessageBox.Show("是否删除?","请确认",MessageBoxButtons.YesNo,MessageBoxIcon.Question) = DialogResult.Yes Then
        Tables("主表").Current.Delete
    End If
End If

 

这样写对吗?甜老师!


--  作者:有点甜
--  发布时间:2014/11/4 14:13:00
--  

 用find好一些

 

http://www.foxtable.com/help/topics/0396.htm