看實例學VFP:模糊查詢時間:2009-02-11 本站 老馬
- 本文是在vfp中使用select語句的like子句的一個例子,關于like子句請參考:select SQL 命令 或sql語言教程。 本例運行時如下圖:
本例用到了“數(shù)據1”數(shù)據庫中的“網站信息表”,關于該數(shù)據庫的情況已經在看實例學VFP:示例數(shù)據庫一文中給出,這里不再詳述。 制作步驟如下: 一、新建表單form1,并將其caption屬性值設為“模糊查詢”,width屬性值設置為290,height屬性值設置為175,AutoCenter屬性值設置為.t.,并將其保存為“模糊查詢.scx”。 二、向表單添加一個grid控件,并將其width屬性值設置為290,height屬性值設置為100。 三、在grid控件的下方添加兩個label控件,將它們的caption屬性值分別設置為“請選擇查找方式”和“請輸入要查找的內容”。 四、在label控件的下方添加一個組合框控件Combo1和一個文本框控件,并將組合框控件的RowSourceType屬性值設置為“1-值”,RowSource屬性值設置為“編號,網站名稱,網站網址”。 五、在文本框的右側再添加兩個命令按鈕command1和command2,并將command1和command2的caption屬性值分別設置為“查找”和“恢復”。 六、對表單上各控件的位置進行適當?shù)恼{整,調整后的表單設計器如下圖:
七、添加事件代碼: (一)表單的unload事件:close data (二)表單的init事件: use 網站信息表
this.Combo1.value="編號"
with thisform.grid1
.recordsource="網站信息表"
.deletemark=.f.
.visible=.t.
(三)“查找”按鈕(command1)的click事件: if empty(thisform.Text1.value)=.f.
go top
a=thisform.Combo1.value
b=alltrim(thisform.Text1.value)
local c as integer
if a="編號"
Select * from 網站信息表 where 編號 like b +"%" into cursor 臨時網站信息表
sele 臨時網站信息表
c=reccount()
if c<1
use
messagebox("數(shù)據庫中不存在您所要查詢的記錄",16,"系統(tǒng)提示")
thisform.command2.click()
return
endif
endif
if a="網站名稱"
Select * from 網站信息表 where 網站名稱 like b +"%" into cursor 臨時網站信息表
sele 臨時網站信息表
c=reccount()
if c<1
use
messagebox("數(shù)據庫中不存在您所要查詢的記錄",16,"系統(tǒng)提示")
thisform.command2.click()
return
endif
endif
if a="網站網址"
Select * from 網站信息表 where 網站網址 like b +"%" into cursor 臨時網站信息表
sele 臨時網站信息表
c=reccount()
if c<1
use
messagebox("數(shù)據庫中不存在您所要查詢的記錄",16,"系統(tǒng)提示")
thisform.command2.click()
return
endif
endif
with thisform.grid1
.width=350
.height=100
.left=10
.recordsource="臨時網站信息表"
.deletemark=.f.
.visible=.t.
.readonly=.t.
.ColumnCount=3
.Column1.Header1.Caption="編號"
.Column1.Header1.BackColor=RGB(255,255,190)
.Column2.Header1.BackColor=RGB(255,255,190)
.Column2.Header1.Caption="網站名稱"
.Column3.Header1.BackColor=RGB(255,255,190)
.Column3.Header1.Caption="網站網址"
.Column1.width=75
.Column2.width=80
.Column3.width=150
endwith
thisform.grid1.Setall("DynamicBackColor","RGB(224,225,255)","Column")
thisform.grid1.setfocus
else
messagebox("請輸入要查找的內容!",16,"系統(tǒng)提示")
thisform.Text1.value=""
thisform.Text1.Setfocus
endif
(四)“恢復”按鈕(command2)的click事件: sele 網站信息表
go top
thisform.Text1.value=""
thisform.Text1.Setfocus
with thisform.grid1
.width=350
.height=100
.left=10
.recordsource="網站信息表"
.visible=.t.
.readonly=.t.
.ColumnCount=3
.Column1.Header1.Caption="編號"
.Column1.Header1.BackColor=RGB(255,255,190)
.Column2.Header1.BackColor=RGB(255,255,190)
.Column2.Header1.Caption="網站名稱"
.Column3.Header1.BackColor=RGB(255,255,190)
.Column3.Header1.Caption="網站網址"
.Column1.width=75
.Column2.width=80
.Column3.width=150
endwith
thisform.grid1.Setall("DynamicBackColor","RGB(224,225,255)","Column")
thisform.refresh
八、運行“模糊查詢.scx”。 參考資料: vfp基礎教程:http:///vfpjc/index0.htm VFP網絡開發(fā):http:///VFPwz/vfpwlkf.htm vfp調用api函數(shù):http:///VFPwz/vfpapi.htm VFP報表打?。篽ttp:///VFPwz/vfpreport.htm VFP常用技術:http:///VFPwz/vfpcyjs.htm VFP經驗匯總:http:///VFPwz/vfpjyhz.htm VFP控件使用:http:///VFPwz/vfpkjsy.htm VFP數(shù)據處理:http:///VFPwz/vfpsjcl.htm 本例代碼在Win2003+VFP6.0環(huán)境下調試通過。 |
|
|
來自: happyngkmw > 《實例學VFP》