以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  模糊查询  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=46697)

--  作者:7032175
--  发布时间:2014/2/27 10:30:00
--  模糊查询
帮助里面的模糊查询,是在代码中写入相对应的列进行模糊查询。
我想在TextBox类型里面指定某个表进行全部列,全部内容的模糊查询,如果按照帮助里面的内容进行更改,就需要把所有列写入代码中,有没有简洁的代码来代替一下,不用输入所有列。

--  作者:Bin
--  发布时间:2014/2/27 10:33:00
--  
for 循环一个个拼接

for each c as col in tables("XX").cols
      Filter = Filter & c.name & " = \'" & .Value & "\' or "
next

最后记得把 最后面的OR 切割掉

Filter=Filter.trim().substring(Filter,length-2,2)

--  作者:Bin
--  发布时间:2014/2/27 10:34:00
--  
模糊查询应该用LIke 自行调整一下.
--  作者:7032175
--  发布时间:2014/2/27 10:45:00
--  
With e.Form
    If e.sender.text <> "输入计划号/订单号查询" Then
Dim txt As String = e.Form.Controls("a").Text
If txt = "" Then
    Tables("合同信息").Filter = ""
 Else
    txt = "\'*" & txt & "*\'"
    Tables("合同信息").Filter = "计划号 Like " & txt & " Or 订单号 Like " & txt & " Or 砖号 Like " & txt 
   End If
End If
End With
老师你帮我改一下谢谢了

--  作者:Bin
--  发布时间:2014/2/27 10:54:00
--  
图片点击可在新窗口打开查看代码就是2楼的代码啊,连套用都不会吗.


With e.Form
    If e.sender.text <> "输入计划号/订单号查询" Then
        Dim txt As String = e.Form.Controls("a").Text
        If txt = "" Then
            Tables("合同信息").Filter = ""
        Else
            Dim Filter As String
            For Each c As Col In Tables("合同信息").cols
                Filter = Filter & c.name & " like \'*" & txt  & "*\' or "
            Next
            Filter=Filter.trim().substring(0,Filter.length-3)
            Tables("合同信息").Filter=Filter
        End If
    End If
End With

--  作者:7032175
--  发布时间:2014/2/27 10:56:00
--  
让老师见笑了
--  作者:7032175
--  发布时间:2014/2/27 10:58:00
--  
老师我还有一个问题就是我的表里面含有日期列,如何解决冲突问题?
--  作者:狐狸爸爸
--  发布时间:2014/2/27 11:01:00
--  

实际上,只有字符列才能Like,加上判断就行:

 

With e.Form
    If e.sender.text <> "输入计划号/订单号查询" Then
        Dim txt As String = e.Form.Controls("a").Text
        If txt = "" Then
            Tables("合同信息").Filter = ""
        Else
            Dim Filter As String
            For Each c As Col In Tables("合同信息").cols
                if c.IsString Then
                     Filter = Filter & c.name & " like \'*" & txt  & "*\' or "
                End if

            Next
            Filter=Filter.trim().substring(0,Filter.length-3)
            Tables("合同信息").Filter=Filter
        End If
    End If
End With


--  作者:Bin
--  发布时间:2014/2/27 11:02:00
--  
With e.Form
    If e.sender.text <> "输入计划号/订单号查询" Then
        Dim txt As String = e.Form.Controls("a").Text
        If txt = "" Then
            Tables("合同信息").Filter = ""
        Else
            Dim Filter As String
            For Each c As Col In Tables("合同信息").cols
                If c.IsDate Then
                    Filter = Filter & "Convert([" & c.name & "],\'System.String\')\' Like \'*" & txt  & "*\' or "
                Else
                    Filter = Filter & c.name & " like \'*" & txt  & "*\' or "
                End If
            Next
            Filter=Filter.trim().substring(0,Filter.length-3)
            Tables("合同信息").Filter=Filter
        End If
    End If
End With

判断一下即可.

 

--  作者:狐狸爸爸
--  发布时间:2014/2/27 11:04:00
--  

还有,既然你输入的查询内容只是计划号或订单号,没有必要遍历所有列,直接指定这两列即可:

 

With e.Form
    If e.sender.text <> "输入计划号/订单号查询" Then
        Dim txt As String = e.Form.Controls("a").Text
        If txt = "" Then
            Tables("合同信息").Filter = ""
        Else
            Tables("合同信息").Filter= “计划号  like \'*" & txt  & "*\' or 订单号 Like \'*" & txt & "*\'"
        End If
    End If
End With

[此贴子已经被作者于2014-2-27 11:04:27编辑过]