Foxtable(狐表)用户栏目专家坐堂 → 多关键词模糊查找


  共有3967人关注过本帖树形打印复制链接

主题:多关键词模糊查找

帅哥哟,离线,有人找我吗?
有点色
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:13837 积分:69650 威望:0 精华:0 注册:2016/11/1 14:42:00
  发帖心情 Post By:2016/12/21 20:04:00 [显示全部帖子]

以下是引用luckbetter333在2016/12/21 19:31:00的发言:
可以多个关键词么?

 

那你就用空格分割多个关键字

 

Dim str As String = e.Form.Controls("TextBox1").Text
Dim filter As String = "1=2"
For Each dc As Col In CurrentTable.Cols
    For Each s As String In str.split(" ")
        filter &= " Or convert(" & dc.Name & ",'System.String') like '%" & s & "%'"
    Next
Next
CurrentTable.Filter = filter


 回到顶部
帅哥哟,离线,有人找我吗?
有点色
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:13837 积分:69650 威望:0 精华:0 注册:2016/11/1 14:42:00
  发帖心情 Post By:2016/12/22 10:43:00 [显示全部帖子]

参考代码

 

Dim str As String = e.Form.Controls("TextBox1").Text
Dim t As Table = Tables("产品模糊查找_Table1")
If str = "" Then
    t.Filter = ""
Else
    Dim ary() As String = str.split(" ")
    Dim idxs As String = "-1,"
    For Each r As DataRow In t.DataTable.dataRows
        Dim count As Integer = 0
        For Each s As String In ary
            For Each c As Col In t.Cols
                If Cstr(r(c.name)).Contains(s) Then
                    count += 1
                    Exit For
                End If
            Next
        Next
        If count = ary.Length Then
            idxs &= r("_Identify") & ","
        End If
    Next
    t.Filter = "_Identify in (" & idxs.Trim(",") & ")"
End If


 回到顶部