以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  如何添加条件筛选?  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=23413)

--  作者:yacity
--  发布时间:2012/9/11 17:03:00
--  如何添加条件筛选?

如下代码

 

 

 

Dim txt As String = e.Form.Controls("TextBox1").Text
Dim tbl As Table = Tables("制袋选产品_Table1")
tbl.Filter= ""
If txt = "" Then
    tbl.Filter = ""
Else
   txt = "\'*" & txt.Replace("*","[*]") & "*\'"
    \'或者 txt = "\'*" & strtowide(txt) & "*\'"

If txt.IndexOf(" ") = -1 Then \'如果没有空格
tbl.filter = " chanpinname Like " & txt & " Or guige Like " & txt & " "
    tbl.Sort = "chanpinname desc,guige desc,danwei desc"

Else
\'Dim txt As String
Dim txt2 As String
Dim txt3 As String
Dim Values() As String
Values = txt.split(" ")
txt2=values(0)& "*\'"
txt3="\'*"& values(1)

    tbl.filter = "chanpinname Like " & txt2 & " And guige Like " & txt3 & " "
    tbl.Sort = "chanpinname desc,guige desc,danwei desc"
\'Messagebox.show(tbl.filter)
End If
End If

 

 

 如果想添加 and fenlei="制袋" 该怎么修改?

chanpinname Like " & txt & " Or guige Like " & txt & "  and fenlei ="制袋" "     

 tbl.Sort = "chanpinname desc,guige desc,danwei desc"

 

这样写代码不规范,该如何写呢?

[此贴子已经被作者于2012-9-11 17:05:36编辑过]

--  作者:yacity
--  发布时间:2012/9/11 17:25:00
--  

这样 也不行

 

tbl.Filter= "fenlei=制袋"
If txt = "" Then
    tbl.Filter = "fenlei=制袋"
Else

 

代码 通过检测 但是运行的时候出错。

[此贴子已经被作者于2012-9-11 17:25:26编辑过]

--  作者:lin_hailun
--  发布时间:2012/9/11 17:27:00
--  
 呃,楼主,字符串记得加单引号

"fenlei = \'制袋\'"

--  作者:yacity
--  发布时间:2012/9/11 17:40:00
--  
谢谢!