Rss & SiteMap

Foxtable(狐表) http://www.foxtable.com

新一代数据库软件,完美融合Access、Foxpro、Excel、vb.net之优势,人人都能掌握的快速软件开发工具!
共13 条记录, 每页显示 10 条, 页签: [1] [2]
[浏览完整版]

标题:自动删除行

1楼
chan1997 发表于:2012/1/8 19:27:00
以下是开发指南中自动复制行的公式

动复制行

定表A有个逻辑列,希望在某行选中此逻辑列时,自动将此行复制到表B。

为此可以将表A的DataColChanged事件代码设置为:

If e.DataCol.Name = "逻辑列名" AndAlso e.DataRow("逻辑列名") = True Then
     Dim dr As DataRow = DataTables("表B").AddNew
    
For Each dc As DataCol In DataTables("B").DataCols
         dr(dc.Name) = e.DataRow(dc.Name)
    
Next
End
If

上面的代码假定表A和表B的结构相同,且列名相同。

如果列名不同,或者只需复制部分列,可以参考下面的代码:

If e.DataCol.Name = "逻辑列名" AndAlso e.DataRow("逻辑列名") = True Then
    Dim nma() As String = {"A1","A2","A3","A4"}
'A表数据来源列

   
Dim nmb() As String = {"B1","B2","B3","B4"} 'B表数据接收列
   
Dim dr As DataRow = DataTables("表B").AddNew
   
For i As Integer = 0 To nma.Length - 1
        dr(nmb(i)) = e.DataRow(nma(i))
   
Next
End
If



如果"逻辑列名"选择以后A表自动复制数据到B表,如果撒消选择后把复制的数据删除,那么以上的公式如何修改?

2楼
小猪鑫鑫 发表于:2012/1/8 20:47:00

楼主:需要在表B 中加入一列"id"

If e.DataCol.Name = "逻辑列名" Then
    If e.DataRow("逻辑列名") = True Then
        Dim dr As DataRow = DataTables("表B").AddNew
        For Each dc As DataCol In DataTables("表B").DataCols
            If dc.name ="id" Then
                dr("id") =e.DataRow("_identify")
            Else
                dr(dc.Name) = e.DataRow(dc.Name)
            End If
        Next
    Else
        Dim tr As DataRow =DataTables("表B").find("id ="& e.DataRow("_identify"))
        If tr IsNot Nothing Then
            tr.delete()
        End If
    End If
End If

3楼
chan1997 发表于:2012/1/9 20:38:00
好像不行,另个ID列作用是什么,能说明一下吗
4楼
实话实说 发表于:2012/1/9 20:51:00

看看这个

 下载信息  [文件大小:   下载次数: ]
图片点击可在新窗口打开查看点击浏览该文件:根据√选数据移动和删除.table

5楼
mr725 发表于:2012/1/9 21:11:00

判断逻辑列= false 后

dr(dc.Name) = e.DataRow(dc.Name)  改为:dr(dc.Name) = nothing

6楼
实话实说 发表于:2012/1/9 21:28:00
以下是引用chan1997在2012-1-9 20:38:00的发言:
好像不行,另个ID列作用是什么,能说明一下吗

4楼表A窗口应是你所要

7楼
chan1997 发表于:2012/1/11 18:34:00
4楼的表A如果是删除行,表B对应记录的行能同时删除,公式该如何修改?
8楼
blackzhu 发表于:2012/1/12 7:37:00
Datatables("表B").Deletefor("列名='" & 表A相对应的条件 & "'")
9楼
chan1997 发表于:2012/1/12 15:58:00
Datatables("表B").Deletefor("列名='" & 表A相对应的条件 & "'")
以上的公式能帮我在4楼的文件表A公式里插入,改成我要的效果吗?
10楼
狐狸爸爸 发表于:2012/1/12 17:46:00

设置表A的DataRowDeleting事件为:

 

Dim dr As DataRow = DataTables("表B").Find("ID = " & e.DataRow("_Identify"))
If dr IsNot Nothing Then
    dr.Delete
End If
dr = DataTables("表C").Find("ID = " & e.DataRow("_Identify"))
If dr IsNot Nothing Then
    dr.Delete
End If

 

这样在表A删除行,会自动删除表B和表C对应的行。

共13 条记录, 每页显示 10 条, 页签: [1] [2]

Copyright © 2000 - 2018 foxtable.com Tel: 4000-810-820 粤ICP备11091905号

Powered By Dvbbs Version 8.3.0
Processed in .03499 s, 3 queries.