以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  [求助]如何让窗口sqlTable表中记录与后台主表同步  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=92745)

--  作者:chh2321
--  发布时间:2016/11/11 16:04:00
--  [求助]如何让窗口sqlTable表中记录与后台主表同步
老师,请教一个问题:窗口1中插入的SQLTable,我想双击SQLTable(窗口1_Table1)中的记录,弹出的编辑窗口(窗口2)中记录是我双击的那条记录。如何让sqlTable的记录与后台主表记录同步呢?因为我的编辑窗口(窗口2)字段绑定的是主表Table2。


已加载数据定位好像还可以,但未加载数据无法正确定位。代码如下,不知错在哪里?(当前表是Table2的sqlTable(窗口1_Table1),Table2已分页加载)


1  If e.Table.Current Is Nothing Then \'如果Current为Nothing

2      Return \'则返回

3  End If

4  Dim wz As Integer

5  Dim dr As DataRow

6  dr = DataTables("Table2").Find("[编号] = \'" & e.Table.Current("编号") & "\' And [日期] = #" & e.Table.Current("日期") & "#")

7  If dr IsNot Nothing Then

8     wz = Tables("Table2").FindRow(dr)

9     If wz >= 0 Then

10        Tables("Table2").Position = wz

11    End If

12  End If


[此贴子已经被作者于2016/11/11 16:05:27编辑过]

--  作者:有点蓝
--  发布时间:2016/11/11 16:53:00
--  
If e.Table.Current Is Nothing Then \'如果Current为Nothing
    Return \'则返回
End If
Dim wz As Integer
Dim dr As DataRow
dr = DataTables("Table2").Find("[编号] = \'" & e.Table.Current("编号") & "\' And [日期] = #" & e.Table.Current("日期") & "#")
If dr Is Nothing Then
    Dim drs =  DataTables("Table2").AppendLoad("[编号] = \'" & e.Table.Current("编号") & "\' And [日期] = #" & e.Table.Current("日期") & "#").
    If drs.count > 0 Then
        dr = drs(0)
    Else
        Return
    End If
End If
wz = Tables("Table2").FindRow(dr)
If wz >= 0 Then
    Tables("Table2").Position = wz
End If

--  作者:chh2321
--  发布时间:2016/11/11 21:45:00
--  
非常感谢“有点蓝”老师,运行上述代码解决了追加后台数据的问题。
但是还有一点小问题,就是双击sqlTable中的记录后,弹出窗体记录总是定位在找到记录集第一个记录上,我想问题应该是出在“dr = drs(0)”代码上。

--  作者:chh2321
--  发布时间:2016/11/11 21:55:00
--  
我的检索可能有问题,因为有可能出现编号相同,日期相同的多个记录
如果我将代码
dr = DataTables("Table2").Find("[编号] = \'" & e.Table.Current("编号") & "\' And [日期] = #" & e.Table.Current("日期") & "#")
改写如下是否可以避免出现这种情况?
dr = DataTables("Table2").Find("[编号] = \'" & e.Table.Current("编号") & "\' And [_Identify] = \'" & e.Table.Current("_Identify") & "\'")

--  作者:chh2321
--  发布时间:2016/11/11 22:13:00
--  
最终代码改成如下,问题得到解决。   非常感谢“有点蓝”老师的帮助!
If e.Table.Current Is Nothing Then \'如果Current为Nothing
    Return \'则返回
End If
Dim wz As Integer
Dim dr As DataRow
dr = DataTables("Table2").Find("[_Identify] = " & e.Table.Current("_Identify"))
If dr Is Nothing Then
    Dim drs =  DataTables("Table2").AppendLoad("[_Identify] = " & e.Table.Current("_Identify"))
    If drs.count > 0 Then
        dr = drs(0)
    Else
        Return
    End If
End If
wz = Tables("Table2").FindRow(dr)
If wz >= 0 Then
    Tables("Table2").Position = wz
End If

--  作者:chh2321
--  发布时间:2016/11/11 22:39:00
--  
不好意思,上述代码使连锁的其他表出现问题,看来还是不能用[_Identity]来查找定位数据。

       请老师指教!

--  作者:有点蓝
--  发布时间:2016/11/12 8:54:00
--  
应该不是[_Identity]的问题,如果是关联表,相关的父子表的记录要同步加载