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