In the case of VFP: the output of the query results as a table or text file and several previous examples of the SELECT statement application, the combo box control Combo1 properties of the data aspect we set this: the RowSourceType property value is set to "N". The RowSource property value is set to department, gender, education, which means that the data source for the combo box control has been fixed at design time. But this kind of processing in some cases is unreasonable, such as this article to do an example: Want to at run time in the combo box control Select "Department", by "department" to query. We already know that there are currently 5 records in the Personnel information table, including 3 personnel and 2 planning departments. If the previous treatment, we can set the RowSourceType property value of the combo box to "N-value", RowSource property value set to "personnel, planning department." But suppose the company later or added some departments, or cut off some departments, and the combo box control RowSource property value has been fixed, run up a problem, you may need to modify the source code. So in practice, this situation can set the combo box control's RowSourceType property value to "2-alias", and then the item that needs to be displayed in the combo box control from the table query out of the tables to generate a table or cursor, Dynamically assign a value to the RowSource property of the combo box control, so that you can solve the problem that you just mentioned. But there's a small problem here. The results of the "Department" field query for the People information table will have 3 personnel and 2 planning departments, that is, there is a duplicate record in the query result, and if you are assigning the combo box control directly to the data source, you can use the mouse to expand the combo box control at run time as follows:
Do you see the problem? You need to filter out the duplicate records. The simple thing to do is to add the DISTINCT keyword to the SELECT statement to filter out duplicate records.
For a SELECT statement, refer to: Select SQL command or the SQL language tutorial. 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 study VFP: sample database is given in the article, the running interface is shown at the end of this article.
Production steps:
A new form, set its Caption property value to "Get started with programming-get rid of duplicate records in query results", set the AutoCenter property value to. T.,width property value is set to 375,height property value set to 250, and the form is saved as " Remove duplicate records from query results. Scx ".
Add a Label control, a combo box control, and a command button control to the form, line the three controls, and set their properties individually:
1. Label control: The Caption property value is set to query criteria.
2, combo box control Combo1:rowsourcetype property value set to "2-alias".
3. The command button control command1:caption the property value to query.
Third, right click the blank space of the form, select the Data Environment command, and 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. For the convenience of writing code, we modify the Name property value of this table control to "GRID1".
Adjust the position of each control on the form appropriately, and the adjusted form Designer is shown in the following illustration:
V. Add event code:
1. Init events for the form:
Select DISTINCT Department from Personnel information table into cursor LSB && use DISTINCT keyword to remove duplicate records
Thisform.combo1.rowsource= "LSB" && assign a data source to a combo box
2. Combo box control Combo1 Interactivechange event: Thisform.command1.click
3. Click event for the "Query" button Command1:
SELECT * From Personnel information table where Department = ALLTRIM (Thisform.combo1.displayvalue);
into cursor LSTs
thisform.grid1.recordsource= "LSTs" && assign a data source to a table
Thisform.refresh
Run "remove duplicate records from query results. 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