Home > Software engineering >  How to realize combox2 controls and cascade query between combox1 controls
How to realize combox2 controls and cascade query between combox1 controls

Time:09-24


How to realize the choosing combox1 control parts of jilin province, combox2 controls shows of jilin province in the city?

CodePudding user response:

Combox can be binding adodc province changes, it is ok to modify adodc query and refresh

CodePudding user response:

Can say more specific

CodePudding user response:

Actually don't need to separate provinces list, at the same table field can increase province,

First in the Form_Load event, fill out the ComboBox1:
 rs. Open the "SELECT DISTINCT provinces FROM yourtable" 
Combo1. Clear
EOF
Do Until the rs.Combo1 AddItem rs! Province
Rs. MoveNext
Loop
Rs. Close
If Combo1. ListCount Then Combo1. ListIndex=0


In the Click event of Combo1:
 rs. Open the "SELECT city FROM yourtable WHERE provinces='" & amp; Combo1. List (Combo1. ListIndex) & amp; "' 
"Combo2. Clear
EOF
Do Until the rs.Combo2 AddItem rs! City
Rs. MoveNext
Loop
Rs. Close
If Combo2. ListCount Then Combo2. ListIndex=0

CodePudding user response:

Of course, it's also useful table, the general is the application of large amount of data, detailed in the table many fields use coding, the upper table is actually stored encoding corresponding relation,

For example:
Beijing 01
Heilongjiang 02
Jilin 03
Liaoning 04
.

CodePudding user response:

Use ADODC, change the method of query SQL has two kinds:

1 direct change RecordSource attributes:
ADODC1. RecordSource="SELECT city FROM yourtable WHERE provinces='" & amp; Combo1. List (Combo1. ListIndex) & amp; "'
"ADODC1. Refresh

2 articulated new rs object
The Set ADODC1. RecordSource=rs
ADODC1. Refresh

CodePudding user response:

1, writing data to combox1
2, the mouse choose combox1, according to the choice of data, as a condition of the query, check database
3, to find out the results, write combox2,

So, it is realized,

CodePudding user response:

 Private Sub Form_Load () 
Combo1. Clear
Adodc1. The ConnectionString=", "connect to the database string, you add
Adodc1. RecordSource="Select * From provinces"
Adodc1. Refresh
The Do While Not Adodc1. You. EOF
Combo1. AddItem Adodc1. You. Fields (" the name of the province ") 'don't know your province field structure of a data table, can such
Adodc1. You. MoveNext
Loop
End Sub


 Private Sub Combo1_Click () 
Combo2. Clear
'to connect to the database, the Form_Load has loaded, there is no need to load again
Adodc1. RecordSource="Select * From" & amp; Combo1. Text & amp; "
"Adodc1. Refresh
The Do While Not Adodc1. You. EOF
Combo2. AddItem Adodc1. You. Fields (" city ")
Adodc1. You. MoveNext
Loop
End Sub


So set your data table, I think is not reasonable, will all the tables of the provinces, combined into one table, field can increase provinces,

CodePudding user response:

Two columns, name, name of the superior, can,

According to the superior name, you can search out all his subordinates, support N layer,
  • Related