看实例学VFP:模糊查询时间:2009-02-11 本站 老马
- 本文是在vfp中使用select语句的like子句的一个例子,关于like子句请参考:select SQL 命令 或sql语言教程。 本例运行时如下图: 本例用到了“数据1”数据库中的“网站信息表”,关于该数据库的情况已经在看实例学VFP:示例数据库一文中给出,这里不再详述。 制作步骤如下: 一、新建表单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属性值分别设置为“查找”和“恢复”。 六、对表单上各控件的位置进行适当的调整,调整后的表单设计器如下图: 七、添加事件代码: (一)表单的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("数据库中不存在您所要查询的记录",16,"系统提示") thisform.command2.click() return endif endif if a="网站名称" Select * from 网站信息表 where 网站名称 like b +"%" into cursor 临时网站信息表 sele 临时网站信息表 c=reccount() if c<1 use messagebox("数据库中不存在您所要查询的记录",16,"系统提示") thisform.command2.click() return endif endif if a="网站网址" Select * from 网站信息表 where 网站网址 like b +"%" into cursor 临时网站信息表 sele 临时网站信息表 c=reccount() if c<1 use messagebox("数据库中不存在您所要查询的记录",16,"系统提示") 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,"系统提示") 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网络开发:http:///VFPwz/vfpwlkf.htm vfp调用api函数:http:///VFPwz/vfpapi.htm VFP报表打印:http:///VFPwz/vfpreport.htm VFP常用技术:http:///VFPwz/vfpcyjs.htm VFP经验汇总:http:///VFPwz/vfpjyhz.htm VFP控件使用:http:///VFPwz/vfpkjsy.htm VFP数据处理:http:///VFPwz/vfpsjcl.htm 本例代码在Win2003+VFP6.0环境下调试通过。 |
|
来自: happyngkmw > 《实例学VFP》