以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  如何跨表取值?  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=157706)

--  作者:lgz518
--  发布时间:2020/10/26 15:09:00
--  如何跨表取值?
如何实“表B”从表"表A"以字段"产品编号",取"产品编号","单价" 的值,从   "表C" 以字段 "产品编号",取"产品编号","品名","数量"  的值?

"表A"  :" 产品编号","单价"
                 PJ-01     ,    10.5
         
"表C" :   "产品编号","品名",  "数量"
               PJ-01     ,  花生 ,  200


最终结果:“表B”"产品编号","品名","数量" ,"单价"
                                PJ-01     ,  花生 ,  200, 10.5


以下代码是单个表取值,如何组合成一个表从多个表取值?

Dim t As Table = e.Form.Controls("表A").Table   
For k As Integer = t.TopRow To t.BottomRow
    Dim r As Row = t.Rows(k)
    If r("选中") = True Then
        Dim nma() As String = {"产品编号","单价"} 
        Dim nmb() As String = {"产品编号","单价"}  
        Dim dr As Row = Tables("表B").AddNew    
        For i As Integer = 0 To nma.Length - 1
            dr(nmb(i)) = r(nma(i))
        Next
    End If
Next


Dim t As Table = e.Form.Controls("表C").Table  
For k As Integer = t.TopRow To t.BottomRow
    Dim r As Row = t.Rows(k)
    If r("选中") = True Then
        Dim nma() As String = {"产品编号","品名","数量"} 
        Dim nmb() As String = {"产品编号","品名","数量"}  
        Dim dr As Row = Tables("表B").AddNew    
        For i As Integer = 0 To nma.Length - 1
            dr(nmb(i)) = r(nma(i))
        Next
    End If
Next


--  作者:有点蓝
--  发布时间:2020/10/26 15:21:00
--  
Dim t As Table = e.Form.Controls("表A").Table   

        Dim nma() As String = {"产品编号","单价"} 
        Dim nmb() As String = {"产品编号","单价"}
Dim nmc() As String = {"品名","数量"} 
For k As Integer = t.TopRow To t.BottomRow
    Dim r As Row = t.Rows(k)
    If r("选中") = True Then  
        Dim dr As Row = Tables("表B").AddNew    
        For i As Integer = 0 To nma.Length - 1
            dr(nmb(i)) = r(nma(i))
        Next
dim drr as datarow = e.Form.Controls("表C").Table.datatable.find("产品编号=\'" & r("产品编号") & "\' and 选中=true")
if drr isnot nothing then
        For i As Integer = 0 To nmc.Length - 1
            dr(nmc(i)) = drr(nmc(i))
        Next
end if
    End If
Next

--  作者:lgz518
--  发布时间:2020/10/26 16:19:00
--  
老师,想"表C"选中输入表B,而 表A直接匹配给值,不用再选中。  下面代码改有错,请老师纠正,谢谢

Dim t As Table = e.Form.Controls("表C").Table  

        Dim nma() As String = {"产品编号", "品名","数量"} 
        Dim nmb() As String = {"产品编号", "品名","数量"}     
Dim nmc() As String = {"单价"} 
For k As Integer = t.TopRow To t.BottomRow
    Dim r As Row = t.Rows(k)
   \' If r("选中") = True Then
        Dim dr As Row = Tables("表B").AddNew    
        For i As Integer = 0 To nma.Length - 1
            dr(nmb(i)) = r(nma(i))
        Next

Dim drr As DataRow = e.Form.Controls("表A").Table.DataTable.find("产品编号=\'" & r("产品编号") & "\' and 选中=true")

If drr IsNot Nothing Then
        For i As Integer = 0 To nmc.Length - 1
            dr(nmc(i)) = drr(nmc(i))
        Next
End If
    \'End If
Next




--  作者:有点蓝
--  发布时间:2020/10/26 16:28:00
--  
提示什么错误?
--  作者:lgz518
--  发布时间:2020/10/26 16:37:00
--  
解决,谢谢
--  作者:lgz518
--  发布时间:2020/10/26 22:34:00
--  
老师,当表B是关联,在窗体上,表B明细表,如表B主表.表B明细表,窗体上的关联的明细表,无显示,不关联的正表是可以显示。这个要如何解决
--  作者:有点蓝
--  发布时间:2020/10/26 22:38:00
--  
关联表和主表都只能在一个地方显示。使用模拟关联:http://www.foxtable.com/webhelp/topics/2222.htm
--  作者:lgz518
--  发布时间:2020/10/26 22:49:00
--  
Dim t As Table = e.Form.Controls("表C").Table  

        Dim nma() As String = {"产品编号", "品名","数量"} 
        Dim nmb() As String = {"产品编号", "品名","数量"}     
Dim nmc() As String = {"单价"} 
For k As Integer = t.TopRow To t.BottomRow
    Dim r As Row = t.Rows(k)
   \' If r("选中") = True Then
此主题相关图片如下:关联表不显示数据.jpg
按此在新窗口浏览图片
        Dim dr As Row = Tables("表B主表.表B明细").AddNew    
        For i As Integer = 0 To nma.Length - 1
            dr(nmb(i)) = r(nma(i))
        Next

Dim drr As DataRow = e.Form.Controls("表A").Table.DataTable.find("产品编号=\'" & r("产品编号") & "\' and 选中=true")

If drr IsNot Nothing Then
        For i As Integer = 0 To nmc.Length - 1
            dr(nmc(i)) = drr(nmc(i))
        Next
End If
    \'End If
Next

--  作者:有点蓝
--  发布时间:2020/10/26 22:59:00
--  
表B主表.表B明细关联表是不是做了筛选?不然新增的数据不可能不显示的。
--  作者:lgz518
--  发布时间:2020/10/27 9:44:00
--  
是的,不知怎么做?