以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  多值筛选  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=86086)

--  作者:kaituozhe
--  发布时间:2016/6/10 9:50:00
--  多值筛选

以下是在窗口中筛选的一段代码,错误的原因是黄色代码,该怎么修改?

 Case "checkedcomboBox1"
        Dim txt As String = e.Form.Controls("checkedcomboBox1").Text
        If txt = "" Then
            tbl.DataTable.loadFilter = ""
            tbl.DataTable.load()
        Else
            Dim lis() As String =txt.Split(",")
            Dim filter As String
            For Each li As String In lis
                filter = "filter & Or   公司名称 Like " & "\'%" & li & "%\'"
            Next
            tbl.DataTable.loadFilter =filter
            tbl.DataTable.load()
        End If


--  作者:大红袍
--  发布时间:2016/6/10 10:31:00
--  
Dim lis() As String = txt.Split(",")
Dim filter As String = “1=2”
For Each li As String In lis
    filter = filter & " Or 公司名称 Like \'%" & li & "%\'"
Next
tbl.DataTable.loadFilter =filter
tbl.DataTable.load()

--  作者:狐狸爸爸
--  发布时间:2016/6/12 9:03:00
--  

知其然,更要知其所以然,楼主参考:

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

 


--  作者:kaituozhe
--  发布时间:2017/10/6 6:33:00
--  

t.Filter = "交易户名 = \'" & .Current("交易户名") & "\'and 资金类型 = \'" & .Current("资金类型") & "\' and 调查项目 = \'" & .Current("调查项目") & "\'"

以上代码中”交易户名“ 和“资金类型”都是多值字段。


--  作者:kaituozhe
--  发布时间:2017/10/6 6:44:00
--  

Dim t As Table =Tables("查证汇总_table1")
    With Tables("查证汇总")
        If .Current Is Nothing AndAlso .Current.Isnull("交易户名") = False AndAlso .Current.Isnull("资金类型") = False AndAlso .Current.Isnull("调查项目") = False Then
            t.Filter = "False"
        Else
            Dim hm() As String = .Current("交易户名").Split(",")

Dim zjlx() As String = .Current("资金类型").Split(",")


                                  t.Filter = "交易户名 in \'" &  hm & "\' and 资金类型 in \'" & zjlx & "\' and 调查项目 = \'" & .Current("调查项目") & "\'"
                   End If

黄色部分应该怎么修改?


--  作者:kaituozhe
--  发布时间:2017/10/6 7:22:00
--  

Dim hms() As String = .Current("户名").Split(",")
            Dim zjlxs() As String = .Current("资金类型").Split(",")
            Dim filterhm As String
            For Each hm As String In hms
                filterhm = filterhm & " 交易户名 = \'" & hm & "\'Or"
            Next
            Dim filterhm1 As String = filterhm.Trim("Or")
            msgbox(filterhm1)
            Dim filterzjlx As String
            For Each zjlx As String In zjlxs
                filterzjlx = filterzjlx & " 资金类型 = \'" & zjlx & "\'Or"
            Next
            Dim filterzjlx1 As String = filterzjlx.Trim("Or")
            msgbox(filterzjlx1)

 

以上代码中为什么末尾的or还是去不掉呢?


--  作者:有点甜
--  发布时间:2017/10/6 10:51:00
--  
Dim t As Table =Tables("查证汇总_table1")
With Tables("查证汇总")
    If .Current Is Nothing AndAlso .Current.Isnull("交易户名") = False AndAlso .Current.Isnull("资金类型") = False AndAlso .Current.Isnull("调查项目") = False Then
        t.Filter = "False"
    Else
        Dim hm As String = .Current("交易户名").replace(",", "\',\'")
        Dim zjlx As String = .Current("资金类型").replace(",", "\',\'")
     
        t.Filter = "交易户名 in (\'" &  hm & "\') and 资金类型 in (\'" & zjlx & "\') and 调查项目 = \'" & .Current("调查项目") & "\'"
    End If
End With