以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  动态筛选表中的数据  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=45041)

--  作者:Siluy_kl1017
--  发布时间:2014/1/14 15:50:00
--  动态筛选表中的数据

【求助】:我想在项目中增加一个泛用模糊查询的界面。即我选择当前表,输入关键字进行模糊查询就要把表中的所有列含有输入的文本加载出来。遇到难题,求助大神们。我写的测试代码如下(写的有问题),请求指点。

 

Dim txt As String = e.Form.Controls("TextBox1").Text
Dim FilterStr As String = ""

If txt = "" Then
    CurrentTable.Filter = ""
Else
    txt = "\'%" & txt & "%\'"
    For i As Integer = 0 To CurrentTable.Cols.Count - 1
        FilterStr  = " \'" & FilterStr & "\' + \'" & CurrentTable.Cols(i).Name & "\' & Like + " & txt & " + or"       
    Next
End If
CurrentTable.Filter = FilterStr

 


--  作者:Bin
--  发布时间:2014/1/14 15:55:00
--  

Dim txt As String = e.Form.Controls("TextBox1").Text
Dim FilterStr As String = ""

If txt = "" Then
    CurrentTable.Filter = ""
Else
    txt = "\'%" & txt & "%\'"
    For i As Integer = 0 To CurrentTable.Cols.Count - 1
        FilterStr  = FilterStr & CurrentTable.Cols(i).Name & " Like " & txt & " or"       
    Next
End If
CurrentTable.Filter = FilterStr.SubString(0,
FilterStr.length-2)


--  作者:Siluy_kl1017
--  发布时间:2014/1/14 16:31:00
--  
谢谢   好像我试了也不行报错。我写的代码从逻辑上有问题嘛? 大神。
--  作者:Bin
--  发布时间:2014/1/14 16:44:00
--  
报什么错? 你直接上例子吧
--  作者:有点甜
--  发布时间:2014/1/14 20:29:00
--  
 如下代码

Dim txt As String = e.Form.Controls("TextBox1").Text

\'Dim txt = "xxxx"
Dim FilterStr As String = ""
If txt = "" Then
    CurrentTable.Filter = ""
Else
    txt = "\'*" & txt & "*\'"
    For i As Integer = 0 To CurrentTable.Cols.Count - 1
        FilterStr += CurrentTable.Cols(i).Name & " Like " & txt & " or "
    Next
    CurrentTable.Filter = filterStr.SubString(0, filterStr.Length-3)
End If