adotable中Filter的用法

2021-05-22 13:21:36 字數 1474 閱讀 3216

當我們在運算元據集時,往往需要對資料進行篩眩例如:乙個名為customer的資料表,它具有custno、custname、country、address、phone、state、taxrate等字段,如果只想檢視國別為china或顧客號大於1000的顧客記錄,就需要對資料集進行過濾。經總結,有下面這些過濾方法:

一、利用ttable和tquery的filter屬性

1.在設計時設定filter屬性

例如,設定filter為:country=′china′然後改變filtered屬性為true(注意,filtered為true時過濾才有效)。則只能看到對應的country欄位內容為『china』的記錄。

設定filter時可以使用的操作符有:<、>、<=、>=、=、<>、and、or、not。

例如,設定filter為:custno>=1000andcustno<=5000,則只能看到顧客號在1000與5000之間的顧客記錄。

2.在程式執行期間進行動態過濾

要在程式執行時改變filter屬性,這包括兩種情況:

(1)操作符右邊為常量,例如:table1filter:=′state′+′=′+′′′hi′′′;

注意:字串常量必須用三對單引號括起來。

(2)操作符右邊不為常量,可能是通過乙個變數指定的值,或由一輸入框給出的值。這時需要用到format函式。其**形式為:table1filter:=format(′state′+′=′+′′′%s′′′,[statevalue]);其中statevalue為已經賦值的乙個字串變數,也可以為其他形式,例如:edit1text。

三、用onfilterrecord事件篩選onfilterrecord事件允許按非鍵控字段建立篩選程式,例如:

procedure tform1.table1filterrecord(dataset:tdataset;varaccept:boolean);

begin

accept:=dataset[′state′]=′ca′;

end;

四、用tquery控制項的sql語句

1.sql語句中不包含變數和引數

select*fromcustomer

wherecustno>=1000and custno<=5000

2.sql語句中包含引數

select*fromcustomer

wherecustno>=:custno

在執行期間給引數custno賦值。

3.sql語句中包含變數

這時向tquery控制項新增sql語句的**應當這樣寫:

query1.close;

query1.sql.clear;

query1.sql.add(format(′select*fromcustomer′+′′+′wherestate=′+′′′%s′′′,[statevalue]));

query1.open;在上面的四種方法中,第四種功能最強大,使用最靈活。

0 0 0

(請您對文章做出評價)

ADOTAble中進行查詢刪除操作

procedure tform1.button1click sender tobject var newstring string begin inputquery 輸入查詢條件 姓名為 newstring adotable1.locate sname newstring,locaseinsensi...

Django的models中filter的各種用法

exact 精確等於 like aaa iexact 精確等於 忽略大小寫 ilike aaa contains 包含 like aaa icontains 包含 忽略大小寫 ilike aaa 但是對於sqlite來說,contains的作用效果等同於icontains。gt 大於 gte 大於等...

Hbase中Filter的使用

組裝查詢條件成hbase 過濾器 public static filter getorderqueryfilter querycondition qc if qc null qc.getpay time end null qc.getpay time end equals if qc null qc...