Look at the case study VFP: more complex query

Source: Internet
Author: User
Tags exit empty query

Looking at the case study VFP: Locating and locating the records in the table and looking at the case study VFP: Create a query with a SELECT statement in two examples, we can select a field to query from the combo box when querying. This example further improves the query by making it possible to select not only the fields to query from a combo box but also the operators (such as <, =, >, and so on) from another combo box to implement more complex queries. This example applies to the Data environment and uses the "People Information table" in the data 1 database as the data source for the data environment, and the situation of the database is already looking at the case of VFP: sample database is given in the article, no longer detailed here. The run interface is shown at the end of this article.

The production steps are as follows:

A new form, set its Caption property value to "more complex query Example", and AutoCenter property value to. T.,width property value set to 520,height property value set to 245, and save as "more complex query example. Scx".

Second, right click the blank space of the form, select the Data Environment command, add the people information table to the data environment. In the Data Environment Designer, drag the title bar of the People information table onto the form to automatically generate a table control. Because it is from the data environment to drag the "People Information table" by the system automatically generated, the table control of the RecordSource property and RecordSourceType property has been set up by the system, regardless of it, but the Name property value system given a good long, in order to write the code of convenience, We modify the Name property value of this table control to "GRID1".

Third, add a Label control below the table control and set its Caption property value to query criteria.

To the right of the label control, add two combo box controls, a text box control, and two command buttons Command1 and Command2, and then set the Caption property values of the two command buttons to find and exit.

To adjust the position of each control on the form, the Adjusted form Designer is shown in the following illustration:

Set the properties of the combo box control:

(a) combo box Combo1:recordsourcetype property value is set to "8-structure" and the RecordSource property value is set to personnel information table.

(ii) combo box Combo2:recordsourcetype property value is set to "N" and the RecordSource property value is set to ",>,<,=,>=,<=,<>".

Vii. Add event code:

(i) Unload event code for the form: close data

(ii) combo box Combo1 Interactivechange event code:

If Alltrim (this.displayvalue) = "Birth date"
   thisform.text1.value={}
else
   thisform.text1.value= '
endif

(iii) The Click event code for the Find button Command1:

If thisform.grid1.recordsource= ' Temporary staff information table ' thisform.grid1.recordsource= ' personnel information table ' endif ' private cxtj if Empty (
   Thisform.combo1.displayvalue) or empty (Thisform.combo2.displayvalue); or empty (thisform.text1.value) && Determine if the list box and text box are empty MessageBox (' Enter the full condition! ', 16, ' system hint ') Thisform.combo1.setfocus else does case alltrim (thisform. Combo1.displayvalue) = ' Basic Salary ' cxtj=alltrim (thisform.combo1.displayvalue);
+ ' +alltrim (thisform.combo2.displayvalue); + ' +alltrim (thisform.text1.value) Case Alltrim (thisform. Combo1.displayvalue) = ' Birth date ' Cxtj=alltrim (Thisform.combo1.displayvalue);
+ ' +alltrim (thisform.combo2.displayvalue); + ' Ctod (' +dtoc (thisform.text1.value) + ' ") ' otherwise Cxtj=alltrim (thisform.combo1.displayvalue);
+ ' +alltrim (thisform.combo2.displayvalue); + ' "' +alltrim (thisform.text1.value) + '" ' endcase Select * from personnel information table where &AMP;CXTJ. into cursor temporary personnel information Table thisform.grid1.recordsource= ' Temporary staff Information table ' Thisform.grid1.backcolor=rgb (200,224,248) endif

(iv) "Exit" button Command2 Click event Code: Thisform.release

Run "more complex query examples. SCX", the interface is shown in the following figure:

Resources:

The basic course of VFP: http://bianceng.cnhttp://www.bianceng.cn/vfpjc/index0.htm

VFP Primary Course: http://bianceng.cnhttp://www.bianceng.cn/cc/index.htm

VFP Intermediate Course: http://bianceng.cnhttp://www.bianceng.cn/mcc/mcc.htm

VFP Advanced Course: http://bianceng.cnhttp://www.bianceng.cn/hcc/hcc.htm

VFP Network Development: http://bianceng.cnhttp://www.bianceng.cn/VFPwz/vfpwlkf.htm

VFP Call API function: http://bianceng.cnhttp://www.bianceng.cn/VFPwz/vfpapi.htm

VFP Report Print: http://bianceng.cnhttp://www.bianceng.cn/VFPwz/vfpreport.htm

VFP Common technique: http://bianceng.cnhttp://www.bianceng.cn/VFPwz/vfpcyjs.htm

VFP Experience Summary: http://bianceng.cnhttp://www.bianceng.cn/VFPwz/vfpjyhz.htm

VFP Control use: http://bianceng.cnhttp://www.bianceng.cn/VFPwz/vfpkjsy.htm

VFP Data processing: http://bianceng.cnhttp://www.bianceng.cn/VFPwz/vfpsjcl.htm

This example code is debugged in the win2003+vfp6.0 environment.

See the full set of "rookie also learn VFP" tutorial

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.