以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  [求助]引用  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=194674)

--  作者:苏州老街
--  发布时间:2025/1/3 21:36:00
--  [求助]引用
老师,下面代码总是重复引用。我把他放在项目事件中的 AfterOpenProject



Dim cmd5 As New SQLCommand          
Dim dt As DataTable
cmd5.Co  nnecti
Dim t5 As Table = Tables("进销存")
Dim filter = iif(t5.filter > "", t5.filter, "1=1")
cmd5.CommandText = "SEL ECT DISTINCT year(日期) as 年, 来源,客户ID,客户名称 from {进销存} where " & filter
dt = cmd5.ExecuteReader()
For Each dr As DataRow In dt.datarows
    filter = "年份 = \'" & dr("年") & "\' and 来源 = \'" & dr("来源") & "\' and 客户名称 = \'" & dr("客户名称") & "\'"
    Dim ndr As DataRow = DataTables("年度统计").find(filter)
    If ndr Is Nothing Then
        ndr = DataTables("年度统计").addnew
    End If
    ndr("年份") = dr("年")
    ndr("来源") = dr("来源")
    ndr("客户名称") = dr("客户名称")
Next

--  作者:有点蓝
--  发布时间:2025/1/4 9:25:00
--  
重复引用】指什么?
--  作者:苏州老街
--  发布时间:2025/1/4 11:55:00
--  
老师,打开项目就会重复复制被引用的字段。

图片点击可在新窗口打开查看此主题相关图片如下:重复复制.jpg
图片点击可在新窗口打开查看

--  作者:有点蓝
--  发布时间:2025/1/4 14:12:00
--  
应该是来源列没有值引起的。参考这里的方法生成查询条件:http://www.foxtable.com/webhelp/topics/1058.htm

Dim Filter As String
    
If dr.isnull("年")=false Then
        Filter = 
"年份 = \'" & dr("年") & "\'"
    
End If

    
If dr.isnull("来源")=false Then
        
If Filter > "" Then
            Filter = Filter & 
" And "
        
End If
        Filter = Filter & 
"来源 = \'" & dr("年") & "\'"
    
End If
……


--  作者:苏州老街
--  发布时间:2025/1/4 16:26:00
--  
老师,是来源值是空引起的。下面代码修改不好。

Dim cmd5 As New SQLCommand          \'年度统计
Dim dt As DataTable
cmd5.C   
Dim t5 As Table = Tables("进销存")
Dim filter = iif(t5.filter > "", t5.filter, "1=1")
cmd5.CommandText = "SEL  CT DISTINCT year(日期) as 年, 来源,客户ID,客户名称 from {进销存} where " & filter
dt = cmd5.ExecuteReader()
For Each dr As DataRow In dt.datarows
    filter = "年份 = \'" & dr("年") & "\' and 来源 = \'" & dr("来源") & "\' and 客户名称 = \'" & dr("客户名称") & "\'"
    Dim ndr As DataRow = DataTables("年度统计").find(filter)
    If ndr Is Nothing Then
        ndr = DataTables("年度统计").addnew
    End If
    ndr("年份") = dr("年")
    ndr("来源") = dr("来源")
    ndr("客户名称") = dr("客户名称")
Next




Dim Filter As String
    If dr.isnull("年")=False Then
        Filter = "年份 = \'" & dr("年") & "\'"
    End If

    If dr.isnull("来源")=False Then
        If Filter > "" Then
            Filter = Filter & " And "
        End If
        Filter = Filter & "来源 = \'" & dr("年") & "\'"
    End If

--  作者:有点蓝
--  发布时间:2025/1/4 16:43:00
--  
For Each dr As DataRow In dt.datarows
Dim Filter As String=""
    If dr.isnull("年")=False Then
        Filter = "年份 = \'" & dr("年") & "\'"
    End If

    If dr.isnull("来源")=False Then
        If Filter > "" Then
            Filter = Filter & " And "
        End If
        Filter = Filter & "来源 = \'" & dr("年") & "\'"
    End If
第三个条件参考上面方式自己学着加
    Dim ndr As DataRow = DataTables("年度统计").find(filter)
    If ndr Is Nothing Then
        ndr = DataTables("年度统计").addnew
    End If
    ndr("年份") = dr("年")
    ndr("来源") = dr("来源")
    ndr("客户名称") = dr("客户名称")
Next