下面這段代碼是檢索一個表中bno這一列=sle_1.text的陳述句
dw_1.setfilter('bno'+'='+"'"+sle_1.text+"'")
dw_1.filter()
但是要實作模糊檢索,應該在哪里加%呢
我對單引號和雙引號的用法也不太清楚,怎么改都實作不了
類似的代碼
如果換成別的列,有中文的,比如"書名"
即使我把書的全名都打進去,也沒有檢索結果
求大牛解答
謝謝了~
uj5u.com熱心網友回復:
Number formatIf the filter expression contains numbers, the DataWindow expects the numbers in U.S. format. In PowerBuilder, be aware that the String function formats numbers using the current system settings. If you use it to build the filter expression, specify a display format that produces U.S. notation.
Escape keyword
If you need to use the % or _ characters as part of the string, you can use the escape keyword to indicate that the character is part of the string. For example, the _ character in the following filter string is part of the string to be searched for, but is treated as a wildcard:
comment LIKE ~'%o_a15progress%~'
The escape keyword designates any character as an escape character (do not use a character that is part of the string you want to match). In the following example, the asterisk (*) character is inserted before the _ character and designated as an escape character, so that the _ character is treated as part of the string to be matched:
comment like ~'%o*_a15progress%~' escape ~'*~'
uj5u.com熱心網友回復:
dw_1.setfilter('bno'+'='+"'"+sle_1.text+"%'")uj5u.com熱心網友回復:
呵呵uj5u.com熱心網友回復:
dw_1.setfilter('bno'+' like '+"'%"+sle_1.text+"%'")uj5u.com熱心網友回復:
dw_1.setfilter('bno'+' like '+"'%"+sle_1.text+"%'")uj5u.com熱心網友回復:
謝謝ls各位如果我要用trim(sle_1.text)的話,改怎么加呢
用dw_1.setfilter('bno'+' like '+"'%"+sle_1.text+"%'") 可以,但是內容換成有漢字的就出不來了,不太明白為什么
uj5u.com熱心網友回復:
怎么能出不來呢我的就是這么就能出來的 dw_1.setfilter('bno'+' like '+"'%"+sle_1.text+"%'")
uj5u.com熱心網友回復:
bno在資料庫里是什么型別的?如果是字串型別的,則
dw_1.setfilter("bno like " + "'%"+ trim(sle_1.text) + "%'")
否則:
dw_1.setfilter("string(bno ) like " + "'%" + trim(sle_1.text)+"%'")
uj5u.com熱心網友回復:
厄...
出來了
前面我有段代碼弄錯了
不好意思哈~
uj5u.com熱心網友回復:
我還是認為雙引號在外層,單引號在里層,代碼可讀性更好dw_1.setfilter("bno like '%" + sle_1.text + "%'")
dw_1.filter()
uj5u.com熱心網友回復:
我總是用一個文本框作為輸出結果看一看內層的值是不是達到要求來判斷uj5u.com熱心網友回復:
呵呵 多謝大家 學習了~轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/100839.html
標籤:數據庫相關
